Skip to content

Remove needless main fn #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/future/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
///
Expand All @@ -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>() -> T {
let fut = Pending {
Expand Down
4 changes: 2 additions & 2 deletions src/future/poll_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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, T>(f: F) -> T
where
Expand Down
4 changes: 2 additions & 2 deletions src/future/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(val: T) -> T {
val
Expand Down
4 changes: 2 additions & 2 deletions src/stream/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +18,7 @@ use crate::task::{Context, Poll};
///
/// assert_eq!(s.next().await, None);
/// #
/// # }) }
/// # })
/// ```
pub fn empty<T>() -> Empty<T> {
Empty {
Expand Down
4 changes: 2 additions & 2 deletions src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +18,7 @@
//! assert_eq!(v, 9);
//! }
//! #
//! # }) }
//! # })
//! ```

use cfg_if::cfg_if;
Expand Down
4 changes: 2 additions & 2 deletions src/stream/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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: T) -> Once<T> {
Once { value: Some(t) }
Expand Down
4 changes: 2 additions & 2 deletions src/stream/repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<T>(item: T) -> Repeat<T>
where
Expand Down
4 changes: 2 additions & 2 deletions src/stream/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +18,7 @@
//! assert_eq!(v, 9);
//! }
//! #
//! # }) }
//! # })
//! ```

mod all;
Expand Down
4 changes: 2 additions & 2 deletions src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//!
Expand All @@ -26,7 +26,7 @@
//!
//! assert_eq!(*m1.lock().await, 1);
//! #
//! # }) }
//! # })
//! ```

#[doc(inline)]
Expand Down
16 changes: 8 additions & 8 deletions src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
///
Expand All @@ -46,7 +46,7 @@ const BLOCKED: usize = 1 << 1;
/// }
/// assert_eq!(*m.lock().await, 10);
/// #
/// # }) }
/// # })
/// ```
pub struct Mutex<T> {
state: AtomicUsize,
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<T> Mutex<T> {
/// # Examples
///
/// ```
/// # fn main() { async_std::task::block_on(async {
/// # async_std::task::block_on(async {
/// #
/// use std::sync::Arc;
///
Expand All @@ -99,7 +99,7 @@ impl<T> Mutex<T> {
///
/// assert_eq!(*m2.lock().await, 20);
/// #
/// # }) }
/// # })
/// ```
pub async fn lock(&self) -> MutexGuard<'_, T> {
pub struct LockFuture<'a, T> {
Expand Down Expand Up @@ -196,7 +196,7 @@ impl<T> Mutex<T> {
/// # Examples
///
/// ```
/// # fn main() { async_std::task::block_on(async {
/// # async_std::task::block_on(async {
/// #
/// use std::sync::Arc;
///
Expand All @@ -217,7 +217,7 @@ impl<T> Mutex<T> {
///
/// assert_eq!(*m2.lock().await, 20);
/// #
/// # }) }
/// # })
/// ```
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>> {
if self.state.fetch_or(LOCK, Ordering::Acquire) & LOCK == 0 {
Expand Down Expand Up @@ -249,15 +249,15 @@ impl<T> Mutex<T> {
/// # Examples
///
/// ```
/// # fn main() { async_std::task::block_on(async {
/// # async_std::task::block_on(async {
/// #
/// use async_std::sync::Mutex;
///
/// let mut mutex = Mutex::new(0);
/// *mutex.get_mut() = 10;
/// assert_eq!(*mutex.lock().await, 10);
/// #
/// # }) }
/// # })
/// ```
pub fn get_mut(&mut self) -> &mut T {
unsafe { &mut *self.value.get() }
Expand Down
24 changes: 12 additions & 12 deletions src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
///
Expand All @@ -51,7 +51,7 @@ const READ_COUNT_MASK: usize = !(ONE_READ - 1);
/// *w += 1;
/// assert_eq!(*w, 6);
/// #
/// # }) }
/// # })
/// ```
pub struct RwLock<T> {
state: AtomicUsize,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<T> RwLock<T> {
/// # Examples
///
/// ```
/// # fn main() { async_std::task::block_on(async {
/// # async_std::task::block_on(async {
/// #
/// use async_std::sync::RwLock;
///
Expand All @@ -100,7 +100,7 @@ impl<T> RwLock<T> {
///
/// assert!(lock.try_read().is_some());
/// #
/// # }) }
/// # })
/// ```
pub async fn read(&self) -> RwLockReadGuard<'_, T> {
pub struct LockFuture<'a, T> {
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<T> RwLock<T> {
/// # Examples
///
/// ```
/// # fn main() { async_std::task::block_on(async {
/// # async_std::task::block_on(async {
/// #
/// use async_std::sync::RwLock;
///
Expand All @@ -222,7 +222,7 @@ impl<T> RwLock<T> {
///
/// assert!(lock.try_read().is_some());
/// #
/// # }) }
/// # })
/// ```
pub fn try_read(&self) -> Option<RwLockReadGuard<'_, T>> {
let mut state = self.state.load(Ordering::Acquire);
Expand Down Expand Up @@ -253,7 +253,7 @@ impl<T> RwLock<T> {
/// # Examples
///
/// ```
/// # fn main() { async_std::task::block_on(async {
/// # async_std::task::block_on(async {
/// #
/// use async_std::sync::RwLock;
///
Expand All @@ -264,7 +264,7 @@ impl<T> RwLock<T> {
///
/// assert!(lock.try_read().is_none());
/// #
/// # }) }
/// # })
/// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
pub struct LockFuture<'a, T> {
Expand Down Expand Up @@ -374,7 +374,7 @@ impl<T> RwLock<T> {
/// # Examples
///
/// ```
/// # fn main() { async_std::task::block_on(async {
/// # async_std::task::block_on(async {
/// #
/// use async_std::sync::RwLock;
///
Expand All @@ -385,7 +385,7 @@ impl<T> RwLock<T> {
///
/// assert!(lock.try_write().is_none());
/// #
/// # }) }
/// # })
/// ```
pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> {
let mut state = self.state.load(Ordering::Acquire);
Expand Down Expand Up @@ -431,15 +431,15 @@ impl<T> RwLock<T> {
/// # Examples
///
/// ```
/// # fn main() { async_std::task::block_on(async {
/// # async_std::task::block_on(async {
/// #
/// use async_std::sync::RwLock;
///
/// let mut lock = RwLock::new(0);
/// *lock.get_mut() = 10;
/// assert_eq!(*lock.write().await, 10);
/// #
/// # }) }
/// # })
/// ```
pub fn get_mut(&mut self) -> &mut T {
unsafe { &mut *self.value.get() }
Expand Down
8 changes: 3 additions & 5 deletions src/task/block_on.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, T>(future: F) -> T
where
Expand Down
8 changes: 4 additions & 4 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//!
Expand All @@ -19,7 +19,7 @@
//! });
//! assert_eq!(handle.await, 3);
//! #
//! # }) }
//! # })
//! ```

#[doc(inline)]
Expand Down Expand Up @@ -64,15 +64,15 @@ pub(crate) mod blocking;
/// Basic usage:
///
/// ```
/// # fn main() { async_std::task::block_on(async {
/// # async_std::task::block_on(async {
/// #
/// use async_std::task;
///
/// task::blocking(async {
/// 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.
Expand Down
Loading