Skip to content

Commit 3f4a56a

Browse files
author
Stjepan Glavina
committed
Reformat doc examples
1 parent 893fd97 commit 3f4a56a

27 files changed

+595
-514
lines changed

src/fs/dir_builder.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,16 @@ impl DirBuilder {
7474
///
7575
/// ```no_run
7676
/// # #![feature(async_await)]
77-
/// use async_std::fs::{metadata, DirBuilder};
78-
///
79-
/// # futures::executor::block_on(async {
80-
/// let path = "/tmp/foo/bar/baz";
77+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
78+
/// #
79+
/// use async_std::fs::DirBuilder;
8180
///
8281
/// DirBuilder::new()
8382
/// .recursive(true)
84-
/// .create(path)
83+
/// .create("/tmp/foo/bar/baz")
8584
/// .await?;
86-
///
87-
/// assert!(metadata(path).await?.is_dir());
88-
/// # std::io::Result::Ok(())
89-
/// # }).unwrap();
85+
/// #
86+
/// # Ok(()) }) }
9087
/// ```
9188
pub fn create<P: AsRef<Path>>(&self, path: P) -> impl Future<Output = io::Result<()>> {
9289
let mut builder = fs::DirBuilder::new();

src/fs/dir_entry.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ impl DirEntry {
7676
///
7777
/// ```no_run
7878
/// # #![feature(async_await)]
79-
/// use async_std::fs::read_dir;
80-
/// use async_std::prelude::*;
79+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
80+
/// #
81+
/// use async_std::{fs, prelude::*};
8182
///
82-
/// # futures::executor::block_on(async {
83-
/// let mut dir = read_dir(".").await?;
83+
/// let mut dir = fs::read_dir(".").await?;
8484
///
8585
/// while let Some(entry) = dir.next().await {
8686
/// let entry = entry?;
8787
/// println!("{:?}", entry.path());
8888
/// }
89-
/// # std::io::Result::Ok(())
90-
/// # }).unwrap();
89+
/// #
90+
/// # Ok(()) }) }
9191
/// ```
9292
pub fn path(&self) -> PathBuf {
9393
self.path.clone()
@@ -101,18 +101,18 @@ impl DirEntry {
101101
///
102102
/// ```no_run
103103
/// # #![feature(async_await)]
104-
/// use async_std::fs::read_dir;
105-
/// use async_std::prelude::*;
104+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
105+
/// #
106+
/// use async_std::{fs, prelude::*};
106107
///
107-
/// # futures::executor::block_on(async {
108-
/// let mut dir = read_dir(".").await?;
108+
/// let mut dir = fs::read_dir(".").await?;
109109
///
110110
/// while let Some(entry) = dir.next().await {
111111
/// let entry = entry?;
112112
/// println!("{:?}", entry.metadata().await?);
113113
/// }
114-
/// # std::io::Result::Ok(())
115-
/// # }).unwrap();
114+
/// #
115+
/// # Ok(()) }) }
116116
/// ```
117117
pub async fn metadata(&self) -> io::Result<fs::Metadata> {
118118
future::poll_fn(|cx| {
@@ -154,18 +154,18 @@ impl DirEntry {
154154
///
155155
/// ```no_run
156156
/// # #![feature(async_await)]
157-
/// use async_std::fs::read_dir;
158-
/// use async_std::prelude::*;
157+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
158+
/// #
159+
/// use async_std::{fs, prelude::*};
159160
///
160-
/// # futures::executor::block_on(async {
161-
/// let mut dir = read_dir(".").await?;
161+
/// let mut dir = fs::read_dir(".").await?;
162162
///
163163
/// while let Some(entry) = dir.next().await {
164164
/// let entry = entry?;
165165
/// println!("{:?}", entry.file_type().await?);
166166
/// }
167-
/// # std::io::Result::Ok(())
168-
/// # }).unwrap();
167+
/// #
168+
/// # Ok(()) }) }
169169
/// ```
170170
pub async fn file_type(&self) -> io::Result<fs::FileType> {
171171
future::poll_fn(|cx| {
@@ -205,18 +205,18 @@ impl DirEntry {
205205
///
206206
/// ```no_run
207207
/// # #![feature(async_await)]
208-
/// use async_std::fs::read_dir;
209-
/// use async_std::prelude::*;
208+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
209+
/// #
210+
/// use async_std::{fs, prelude::*};
210211
///
211-
/// # futures::executor::block_on(async {
212-
/// let mut dir = read_dir(".").await?;
212+
/// let mut dir = fs::read_dir(".").await?;
213213
///
214214
/// while let Some(entry) = dir.next().await {
215215
/// let entry = entry?;
216216
/// println!("{:?}", entry.file_name());
217217
/// }
218-
/// # std::io::Result::Ok(())
219-
/// # }).unwrap();
218+
/// #
219+
/// # Ok(()) }) }
220220
/// ```
221221
pub fn file_name(&self) -> OsString {
222222
self.file_name.clone()

src/fs/file.rs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,31 @@ use crate::task::blocking;
3434
///
3535
/// ```no_run
3636
/// # #![feature(async_await)]
37+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
38+
/// #
3739
/// use async_std::fs::File;
3840
/// use async_std::prelude::*;
3941
///
40-
/// # futures::executor::block_on(async {
4142
/// let mut file = File::create("foo.txt").await?;
4243
/// file.write_all(b"Hello, world!").await?;
43-
/// # std::io::Result::Ok(())
44-
/// # }).unwrap();
44+
/// #
45+
/// # Ok(()) }) }
4546
/// ```
4647
///
4748
/// Read the contents of a file into a `Vec<u8>`:
4849
///
4950
/// ```no_run
5051
/// # #![feature(async_await)]
52+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
53+
/// #
5154
/// use async_std::fs::File;
5255
/// use async_std::prelude::*;
5356
///
54-
/// # futures::executor::block_on(async {
5557
/// let mut file = File::open("foo.txt").await?;
5658
/// let mut contents = Vec::new();
5759
/// file.read_to_end(&mut contents).await?;
58-
/// # std::io::Result::Ok(())
59-
/// # }).unwrap();
60+
/// #
61+
/// # Ok(()) }) }
6062
/// ```
6163
#[derive(Debug)]
6264
pub struct File {
@@ -123,12 +125,13 @@ impl File {
123125
///
124126
/// ```no_run
125127
/// # #![feature(async_await)]
128+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
129+
/// #
126130
/// use async_std::fs::File;
127131
///
128-
/// # futures::executor::block_on(async {
129132
/// let file = File::open("foo.txt").await?;
130-
/// # std::io::Result::Ok(())
131-
/// # }).unwrap();
133+
/// #
134+
/// # Ok(()) }) }
132135
/// ```
133136
pub async fn open<P: AsRef<Path>>(path: P) -> io::Result<File> {
134137
let path = path.as_ref().to_owned();
@@ -169,12 +172,13 @@ impl File {
169172
///
170173
/// ```no_run
171174
/// # #![feature(async_await)]
175+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
176+
/// #
172177
/// use async_std::fs::File;
173178
///
174-
/// # futures::executor::block_on(async {
175179
/// let file = File::create("foo.txt").await?;
176-
/// # std::io::Result::Ok(())
177-
/// # }).unwrap();
180+
/// #
181+
/// # Ok(()) }) }
178182
/// ```
179183
pub async fn create<P: AsRef<Path>>(path: P) -> io::Result<File> {
180184
let path = path.as_ref().to_owned();
@@ -215,15 +219,16 @@ impl File {
215219
///
216220
/// ```no_run
217221
/// # #![feature(async_await)]
222+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
223+
/// #
218224
/// use async_std::fs::File;
219225
/// use async_std::prelude::*;
220226
///
221-
/// # futures::executor::block_on(async {
222227
/// let mut file = File::create("foo.txt").await?;
223228
/// file.write_all(b"Hello, world!").await?;
224229
/// file.sync_all().await?;
225-
/// # std::io::Result::Ok(())
226-
/// # }).unwrap();
230+
/// #
231+
/// # Ok(()) }) }
227232
/// ```
228233
pub async fn sync_all(&self) -> io::Result<()> {
229234
future::poll_fn(|cx| {
@@ -270,15 +275,16 @@ impl File {
270275
///
271276
/// ```no_run
272277
/// # #![feature(async_await)]
278+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
279+
/// #
273280
/// use async_std::fs::File;
274281
/// use async_std::prelude::*;
275282
///
276-
/// # futures::executor::block_on(async {
277283
/// let mut file = File::create("foo.txt").await?;
278284
/// file.write_all(b"Hello, world!").await?;
279285
/// file.sync_data().await?;
280-
/// # std::io::Result::Ok(())
281-
/// # }).unwrap();
286+
/// #
287+
/// # Ok(()) }) }
282288
/// ```
283289
pub async fn sync_data(&self) -> io::Result<()> {
284290
future::poll_fn(|cx| {
@@ -329,14 +335,15 @@ impl File {
329335
///
330336
/// ```no_run
331337
/// # #![feature(async_await)]
338+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
339+
/// #
332340
/// use async_std::fs::File;
333341
/// use async_std::prelude::*;
334342
///
335-
/// # futures::executor::block_on(async {
336343
/// let mut file = File::create("foo.txt").await?;
337344
/// file.set_len(10).await?;
338-
/// # std::io::Result::Ok(())
339-
/// # }).unwrap();
345+
/// #
346+
/// # Ok(()) }) }
340347
/// ```
341348
pub async fn set_len(&self, size: u64) -> io::Result<()> {
342349
future::poll_fn(|cx| {
@@ -376,13 +383,14 @@ impl File {
376383
///
377384
/// ```no_run
378385
/// # #![feature(async_await)]
386+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
387+
/// #
379388
/// use async_std::fs::File;
380389
///
381-
/// # futures::executor::block_on(async {
382390
/// let file = File::open("foo.txt").await?;
383391
/// let metadata = file.metadata().await?;
384-
/// # std::io::Result::Ok(())
385-
/// # }).unwrap();
392+
/// #
393+
/// # Ok(()) }) }
386394
/// ```
387395
pub async fn metadata(&self) -> io::Result<fs::Metadata> {
388396
future::poll_fn(|cx| {
@@ -427,16 +435,17 @@ impl File {
427435
///
428436
/// ```no_run
429437
/// # #![feature(async_await)]
438+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
439+
/// #
430440
/// use async_std::fs::File;
431441
/// use async_std::prelude::*;
432442
///
433-
/// # futures::executor::block_on(async {
434443
/// let mut file = File::create("foo.txt").await?;
435444
/// let mut perms = file.metadata().await?.permissions();
436445
/// perms.set_readonly(true);
437446
/// file.set_permissions(perms).await?;
438-
/// # std::io::Result::Ok(())
439-
/// # }).unwrap();
447+
/// #
448+
/// # Ok(()) }) }
440449
/// ```
441450
pub async fn set_permissions(&self, perm: fs::Permissions) -> io::Result<()> {
442451
let mut perm = Some(perm);

0 commit comments

Comments
 (0)