@@ -34,29 +34,31 @@ use crate::task::blocking;
34
34
///
35
35
/// ```no_run
36
36
/// # #![feature(async_await)]
37
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
38
+ /// #
37
39
/// use async_std::fs::File;
38
40
/// use async_std::prelude::*;
39
41
///
40
- /// # futures::executor::block_on(async {
41
42
/// let mut file = File::create("foo.txt").await?;
42
43
/// file.write_all(b"Hello, world!").await?;
43
- /// # std::io::Result::Ok(())
44
- /// # }).unwrap();
44
+ /// #
45
+ /// # Ok(()) }) }
45
46
/// ```
46
47
///
47
48
/// Read the contents of a file into a `Vec<u8>`:
48
49
///
49
50
/// ```no_run
50
51
/// # #![feature(async_await)]
52
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
53
+ /// #
51
54
/// use async_std::fs::File;
52
55
/// use async_std::prelude::*;
53
56
///
54
- /// # futures::executor::block_on(async {
55
57
/// let mut file = File::open("foo.txt").await?;
56
58
/// let mut contents = Vec::new();
57
59
/// file.read_to_end(&mut contents).await?;
58
- /// # std::io::Result::Ok(())
59
- /// # }).unwrap();
60
+ /// #
61
+ /// # Ok(()) }) }
60
62
/// ```
61
63
#[ derive( Debug ) ]
62
64
pub struct File {
@@ -123,12 +125,13 @@ impl File {
123
125
///
124
126
/// ```no_run
125
127
/// # #![feature(async_await)]
128
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
129
+ /// #
126
130
/// use async_std::fs::File;
127
131
///
128
- /// # futures::executor::block_on(async {
129
132
/// let file = File::open("foo.txt").await?;
130
- /// # std::io::Result::Ok(())
131
- /// # }).unwrap();
133
+ /// #
134
+ /// # Ok(()) }) }
132
135
/// ```
133
136
pub async fn open < P : AsRef < Path > > ( path : P ) -> io:: Result < File > {
134
137
let path = path. as_ref ( ) . to_owned ( ) ;
@@ -169,12 +172,13 @@ impl File {
169
172
///
170
173
/// ```no_run
171
174
/// # #![feature(async_await)]
175
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
176
+ /// #
172
177
/// use async_std::fs::File;
173
178
///
174
- /// # futures::executor::block_on(async {
175
179
/// let file = File::create("foo.txt").await?;
176
- /// # std::io::Result::Ok(())
177
- /// # }).unwrap();
180
+ /// #
181
+ /// # Ok(()) }) }
178
182
/// ```
179
183
pub async fn create < P : AsRef < Path > > ( path : P ) -> io:: Result < File > {
180
184
let path = path. as_ref ( ) . to_owned ( ) ;
@@ -215,15 +219,16 @@ impl File {
215
219
///
216
220
/// ```no_run
217
221
/// # #![feature(async_await)]
222
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
223
+ /// #
218
224
/// use async_std::fs::File;
219
225
/// use async_std::prelude::*;
220
226
///
221
- /// # futures::executor::block_on(async {
222
227
/// let mut file = File::create("foo.txt").await?;
223
228
/// file.write_all(b"Hello, world!").await?;
224
229
/// file.sync_all().await?;
225
- /// # std::io::Result::Ok(())
226
- /// # }).unwrap();
230
+ /// #
231
+ /// # Ok(()) }) }
227
232
/// ```
228
233
pub async fn sync_all ( & self ) -> io:: Result < ( ) > {
229
234
future:: poll_fn ( |cx| {
@@ -270,15 +275,16 @@ impl File {
270
275
///
271
276
/// ```no_run
272
277
/// # #![feature(async_await)]
278
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
279
+ /// #
273
280
/// use async_std::fs::File;
274
281
/// use async_std::prelude::*;
275
282
///
276
- /// # futures::executor::block_on(async {
277
283
/// let mut file = File::create("foo.txt").await?;
278
284
/// file.write_all(b"Hello, world!").await?;
279
285
/// file.sync_data().await?;
280
- /// # std::io::Result::Ok(())
281
- /// # }).unwrap();
286
+ /// #
287
+ /// # Ok(()) }) }
282
288
/// ```
283
289
pub async fn sync_data ( & self ) -> io:: Result < ( ) > {
284
290
future:: poll_fn ( |cx| {
@@ -329,14 +335,15 @@ impl File {
329
335
///
330
336
/// ```no_run
331
337
/// # #![feature(async_await)]
338
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
339
+ /// #
332
340
/// use async_std::fs::File;
333
341
/// use async_std::prelude::*;
334
342
///
335
- /// # futures::executor::block_on(async {
336
343
/// let mut file = File::create("foo.txt").await?;
337
344
/// file.set_len(10).await?;
338
- /// # std::io::Result::Ok(())
339
- /// # }).unwrap();
345
+ /// #
346
+ /// # Ok(()) }) }
340
347
/// ```
341
348
pub async fn set_len ( & self , size : u64 ) -> io:: Result < ( ) > {
342
349
future:: poll_fn ( |cx| {
@@ -376,13 +383,14 @@ impl File {
376
383
///
377
384
/// ```no_run
378
385
/// # #![feature(async_await)]
386
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
387
+ /// #
379
388
/// use async_std::fs::File;
380
389
///
381
- /// # futures::executor::block_on(async {
382
390
/// let file = File::open("foo.txt").await?;
383
391
/// let metadata = file.metadata().await?;
384
- /// # std::io::Result::Ok(())
385
- /// # }).unwrap();
392
+ /// #
393
+ /// # Ok(()) }) }
386
394
/// ```
387
395
pub async fn metadata ( & self ) -> io:: Result < fs:: Metadata > {
388
396
future:: poll_fn ( |cx| {
@@ -427,16 +435,17 @@ impl File {
427
435
///
428
436
/// ```no_run
429
437
/// # #![feature(async_await)]
438
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
439
+ /// #
430
440
/// use async_std::fs::File;
431
441
/// use async_std::prelude::*;
432
442
///
433
- /// # futures::executor::block_on(async {
434
443
/// let mut file = File::create("foo.txt").await?;
435
444
/// let mut perms = file.metadata().await?.permissions();
436
445
/// perms.set_readonly(true);
437
446
/// file.set_permissions(perms).await?;
438
- /// # std::io::Result::Ok(())
439
- /// # }).unwrap();
447
+ /// #
448
+ /// # Ok(()) }) }
440
449
/// ```
441
450
pub async fn set_permissions ( & self , perm : fs:: Permissions ) -> io:: Result < ( ) > {
442
451
let mut perm = Some ( perm) ;
0 commit comments