From 9d9543c46b21e3fee7e2dca9fbe09b00539820bb Mon Sep 17 00:00:00 2001 From: k-nasa Date: Sun, 13 Oct 2019 16:33:02 +0900 Subject: [PATCH] refactor: Remove needless main fn --- src/future/pending.rs | 4 ++-- src/future/poll_fn.rs | 4 ++-- src/future/ready.rs | 4 ++-- src/stream/empty.rs | 4 ++-- src/stream/mod.rs | 4 ++-- src/stream/once.rs | 4 ++-- src/stream/repeat.rs | 4 ++-- src/stream/stream/mod.rs | 4 ++-- src/sync/mod.rs | 4 ++-- src/sync/mutex.rs | 16 ++++++++-------- src/sync/rwlock.rs | 24 ++++++++++++------------ src/task/block_on.rs | 8 +++----- src/task/mod.rs | 8 ++++---- src/task/pool.rs | 4 ++-- src/task/sleep.rs | 4 ++-- src/task/task.rs | 4 ++-- src/task/worker.rs | 4 ++-- 17 files changed, 53 insertions(+), 55 deletions(-) diff --git a/src/future/pending.rs b/src/future/pending.rs index aaee706..2138a30 100644 --- a/src/future/pending.rs +++ b/src/future/pending.rs @@ -9,7 +9,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use std::time::Duration; /// @@ -22,7 +22,7 @@ use crate::task::{Context, Poll}; /// let res: io::Result<()> = io::timeout(dur, fut).await; /// assert!(res.is_err()); /// # -/// # }) } +/// # }) /// ``` pub async fn pending() -> T { let fut = Pending { diff --git a/src/future/poll_fn.rs b/src/future/poll_fn.rs index 116e71c..a808f97 100644 --- a/src/future/poll_fn.rs +++ b/src/future/poll_fn.rs @@ -10,7 +10,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use async_std::future; /// use async_std::task::{Context, Poll}; @@ -21,7 +21,7 @@ use crate::task::{Context, Poll}; /// /// assert_eq!(future::poll_fn(poll_greeting).await, "hello world"); /// # -/// # }) } +/// # }) /// ``` pub async fn poll_fn(f: F) -> T where diff --git a/src/future/ready.rs b/src/future/ready.rs index 04f37b8..65cba56 100644 --- a/src/future/ready.rs +++ b/src/future/ready.rs @@ -7,13 +7,13 @@ /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use async_std::future; /// /// assert_eq!(future::ready(10).await, 10); /// # -/// # }) } +/// # }) /// ``` pub async fn ready(val: T) -> T { val diff --git a/src/stream/empty.rs b/src/stream/empty.rs index c9deea8..ceb91fe 100644 --- a/src/stream/empty.rs +++ b/src/stream/empty.rs @@ -9,7 +9,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use async_std::prelude::*; /// use async_std::stream; @@ -18,7 +18,7 @@ use crate::task::{Context, Poll}; /// /// assert_eq!(s.next().await, None); /// # -/// # }) } +/// # }) /// ``` pub fn empty() -> Empty { Empty { diff --git a/src/stream/mod.rs b/src/stream/mod.rs index 8aa12a2..3d1b103 100644 --- a/src/stream/mod.rs +++ b/src/stream/mod.rs @@ -7,7 +7,7 @@ //! # Examples //! //! ``` -//! # fn main() { async_std::task::block_on(async { +//! # async_std::task::block_on(async { //! # //! use async_std::prelude::*; //! use async_std::stream; @@ -18,7 +18,7 @@ //! assert_eq!(v, 9); //! } //! # -//! # }) } +//! # }) //! ``` use cfg_if::cfg_if; diff --git a/src/stream/once.rs b/src/stream/once.rs index 133a155..be875e4 100644 --- a/src/stream/once.rs +++ b/src/stream/once.rs @@ -8,7 +8,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use async_std::prelude::*; /// use async_std::stream; @@ -18,7 +18,7 @@ use crate::task::{Context, Poll}; /// assert_eq!(s.next().await, Some(7)); /// assert_eq!(s.next().await, None); /// # -/// # }) } +/// # }) /// ``` pub fn once(t: T) -> Once { Once { value: Some(t) } diff --git a/src/stream/repeat.rs b/src/stream/repeat.rs index 1a6da41..75fd697 100644 --- a/src/stream/repeat.rs +++ b/src/stream/repeat.rs @@ -8,7 +8,7 @@ use crate::task::{Context, Poll}; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use async_std::prelude::*; /// use async_std::stream; @@ -18,7 +18,7 @@ use crate::task::{Context, Poll}; /// assert_eq!(s.next().await, Some(7)); /// assert_eq!(s.next().await, Some(7)); /// # -/// # }) } +/// # }) /// ``` pub fn repeat(item: T) -> Repeat where diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index 8849605..1bb0d31 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -7,7 +7,7 @@ //! # Examples //! //! ``` -//! # fn main() { async_std::task::block_on(async { +//! # async_std::task::block_on(async { //! # //! use async_std::prelude::*; //! use async_std::stream; @@ -18,7 +18,7 @@ //! assert_eq!(v, 9); //! } //! # -//! # }) } +//! # }) //! ``` mod all; diff --git a/src/sync/mod.rs b/src/sync/mod.rs index df1d71a..3d3b7b8 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -9,7 +9,7 @@ //! Spawn a task that updates an integer protected by a mutex: //! //! ``` -//! # fn main() { async_std::task::block_on(async { +//! # async_std::task::block_on(async { //! # //! use std::sync::Arc; //! @@ -26,7 +26,7 @@ //! //! assert_eq!(*m1.lock().await, 1); //! # -//! # }) } +//! # }) //! ``` #[doc(inline)] diff --git a/src/sync/mutex.rs b/src/sync/mutex.rs index 673eb83..cd7a357 100644 --- a/src/sync/mutex.rs +++ b/src/sync/mutex.rs @@ -24,7 +24,7 @@ const BLOCKED: usize = 1 << 1; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use std::sync::Arc; /// @@ -46,7 +46,7 @@ const BLOCKED: usize = 1 << 1; /// } /// assert_eq!(*m.lock().await, 10); /// # -/// # }) } +/// # }) /// ``` pub struct Mutex { state: AtomicUsize, @@ -82,7 +82,7 @@ impl Mutex { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # async_std::task::block_on(async { /// # /// use std::sync::Arc; /// @@ -99,7 +99,7 @@ impl Mutex { /// /// assert_eq!(*m2.lock().await, 20); /// # - /// # }) } + /// # }) /// ``` pub async fn lock(&self) -> MutexGuard<'_, T> { pub struct LockFuture<'a, T> { @@ -196,7 +196,7 @@ impl Mutex { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # async_std::task::block_on(async { /// # /// use std::sync::Arc; /// @@ -217,7 +217,7 @@ impl Mutex { /// /// assert_eq!(*m2.lock().await, 20); /// # - /// # }) } + /// # }) /// ``` pub fn try_lock(&self) -> Option> { if self.state.fetch_or(LOCK, Ordering::Acquire) & LOCK == 0 { @@ -249,7 +249,7 @@ impl Mutex { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # async_std::task::block_on(async { /// # /// use async_std::sync::Mutex; /// @@ -257,7 +257,7 @@ impl Mutex { /// *mutex.get_mut() = 10; /// assert_eq!(*mutex.lock().await, 10); /// # - /// # }) } + /// # }) /// ``` pub fn get_mut(&mut self) -> &mut T { unsafe { &mut *self.value.get() } diff --git a/src/sync/rwlock.rs b/src/sync/rwlock.rs index 55a29fc..ed1d218 100644 --- a/src/sync/rwlock.rs +++ b/src/sync/rwlock.rs @@ -33,7 +33,7 @@ const READ_COUNT_MASK: usize = !(ONE_READ - 1); /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use async_std::sync::RwLock; /// @@ -51,7 +51,7 @@ const READ_COUNT_MASK: usize = !(ONE_READ - 1); /// *w += 1; /// assert_eq!(*w, 6); /// # -/// # }) } +/// # }) /// ``` pub struct RwLock { state: AtomicUsize, @@ -89,7 +89,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # async_std::task::block_on(async { /// # /// use async_std::sync::RwLock; /// @@ -100,7 +100,7 @@ impl RwLock { /// /// assert!(lock.try_read().is_some()); /// # - /// # }) } + /// # }) /// ``` pub async fn read(&self) -> RwLockReadGuard<'_, T> { pub struct LockFuture<'a, T> { @@ -211,7 +211,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # async_std::task::block_on(async { /// # /// use async_std::sync::RwLock; /// @@ -222,7 +222,7 @@ impl RwLock { /// /// assert!(lock.try_read().is_some()); /// # - /// # }) } + /// # }) /// ``` pub fn try_read(&self) -> Option> { let mut state = self.state.load(Ordering::Acquire); @@ -253,7 +253,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # async_std::task::block_on(async { /// # /// use async_std::sync::RwLock; /// @@ -264,7 +264,7 @@ impl RwLock { /// /// assert!(lock.try_read().is_none()); /// # - /// # }) } + /// # }) /// ``` pub async fn write(&self) -> RwLockWriteGuard<'_, T> { pub struct LockFuture<'a, T> { @@ -374,7 +374,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # async_std::task::block_on(async { /// # /// use async_std::sync::RwLock; /// @@ -385,7 +385,7 @@ impl RwLock { /// /// assert!(lock.try_write().is_none()); /// # - /// # }) } + /// # }) /// ``` pub fn try_write(&self) -> Option> { let mut state = self.state.load(Ordering::Acquire); @@ -431,7 +431,7 @@ impl RwLock { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # async_std::task::block_on(async { /// # /// use async_std::sync::RwLock; /// @@ -439,7 +439,7 @@ impl RwLock { /// *lock.get_mut() = 10; /// assert_eq!(*lock.write().await, 10); /// # - /// # }) } + /// # }) /// ``` pub fn get_mut(&mut self) -> &mut T { unsafe { &mut *self.value.get() } diff --git a/src/task/block_on.rs b/src/task/block_on.rs index 1150400..31588c4 100644 --- a/src/task/block_on.rs +++ b/src/task/block_on.rs @@ -31,11 +31,9 @@ use kv_log_macro::trace; /// ```no_run /// use async_std::task; /// -/// fn main() { -/// task::block_on(async { -/// println!("Hello, world!"); -/// }) -/// } +/// task::block_on(async { +/// println!("Hello, world!"); +/// }) /// ``` pub fn block_on(future: F) -> T where diff --git a/src/task/mod.rs b/src/task/mod.rs index a14e5d5..1f172c1 100644 --- a/src/task/mod.rs +++ b/src/task/mod.rs @@ -10,7 +10,7 @@ //! Spawn a task and await its result: //! //! ``` -//! # fn main() { async_std::task::block_on(async { +//! # async_std::task::block_on(async { //! # //! use async_std::task; //! @@ -19,7 +19,7 @@ //! }); //! assert_eq!(handle.await, 3); //! # -//! # }) } +//! # }) //! ``` #[doc(inline)] @@ -64,7 +64,7 @@ pub(crate) mod blocking; /// Basic usage: /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use async_std::task; /// @@ -72,7 +72,7 @@ pub(crate) mod blocking; /// println!("long-running task here"); /// }).await; /// # -/// # }) } +/// # }) /// ``` // Once this function stabilizes we should merge `blocking::spawn` into this so // all code in our crate uses `task::blocking` too. diff --git a/src/task/pool.rs b/src/task/pool.rs index 49fbfe4..bfaa17d 100644 --- a/src/task/pool.rs +++ b/src/task/pool.rs @@ -22,7 +22,7 @@ use crate::utils::abort_on_panic; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use async_std::task; /// @@ -32,7 +32,7 @@ use crate::utils::abort_on_panic; /// /// assert_eq!(handle.await, 3); /// # -/// # }) } +/// # }) /// ``` pub fn spawn(future: F) -> JoinHandle where diff --git a/src/task/sleep.rs b/src/task/sleep.rs index 9db09ff..3e98755 100644 --- a/src/task/sleep.rs +++ b/src/task/sleep.rs @@ -14,7 +14,7 @@ use crate::io; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use std::time::Duration; /// @@ -22,7 +22,7 @@ use crate::io; /// /// task::sleep(Duration::from_secs(1)).await; /// # -/// # }) } +/// # }) /// ``` pub async fn sleep(dur: Duration) { let _: io::Result<()> = io::timeout(dur, future::pending()).await; diff --git a/src/task/task.rs b/src/task/task.rs index ba808aa..5100af4 100644 --- a/src/task/task.rs +++ b/src/task/task.rs @@ -68,7 +68,7 @@ impl JoinHandle { /// # Examples /// /// ``` - /// # fn main() { async_std::task::block_on(async { + /// # async_std::task::block_on(async { /// # /// use async_std::task; /// @@ -77,7 +77,7 @@ impl JoinHandle { /// }); /// println!("id = {}", handle.task().id()); /// # - /// # }) } + /// # }) pub fn task(&self) -> &Task { self.0.tag().task() } diff --git a/src/task/worker.rs b/src/task/worker.rs index fc2a6e7..f7b08e1 100644 --- a/src/task/worker.rs +++ b/src/task/worker.rs @@ -22,13 +22,13 @@ use crate::utils::abort_on_panic; /// # Examples /// /// ``` -/// # fn main() { async_std::task::block_on(async { +/// # async_std::task::block_on(async { /// # /// use async_std::task; /// /// println!("The name of this task is {:?}", task::current().name()); /// # -/// # }) } +/// # }) /// ``` pub fn current() -> Task { get_task(|task| task.clone()).expect("`task::current()` called outside the context of a task")