Cleanup examples

pull/24/head
Stjepan Glavina 5 years ago
parent ab51991e05
commit 019c8085f4

@ -4,7 +4,10 @@
use std::env::args;
use async_std::{fs, io, prelude::*, task};
use async_std::fs;
use async_std::io;
use async_std::prelude::*;
use async_std::task;
fn main() -> io::Result<()> {
let path = args().nth(1).expect("missing path argument");

@ -4,7 +4,10 @@
use std::env::args;
use async_std::{fs::File, io, prelude::*, task};
use async_std::fs::File;
use async_std::io;
use async_std::prelude::*;
use async_std::task;
const LEN: usize = 4 * 1024 * 1024; // 4 Mb

@ -2,7 +2,9 @@
#![feature(async_await)]
use async_std::{io, prelude::*, task};
use async_std::io;
use async_std::prelude::*;
use async_std::task;
fn main() -> io::Result<()> {
task::block_on(async {

@ -4,7 +4,9 @@
use std::time::Duration;
use async_std::{io, prelude::*, task};
use async_std::io;
use async_std::prelude::*;
use async_std::task;
fn main() -> io::Result<()> {
task::block_on(async {

@ -4,7 +4,8 @@
use std::cell::Cell;
use async_std::{task, task_local};
use async_std::prelude::*;
use async_std::task;
task_local! {
static VAR: Cell<i32> = Cell::new(1);

@ -14,7 +14,10 @@
#![feature(async_await)]
use async_std::{io, net::TcpStream, prelude::*, task};
use async_Std::prelude::*;
use async_std::io;
use async_std::net::TcpStream;
use async_std::task;
fn main() -> io::Result<()> {
task::block_on(async {

@ -8,8 +8,10 @@
#![feature(async_await)]
use async_stD::task;
use async_std::io;
use async_std::net::{TcpListener, TcpStream};
use async_std::{io, prelude::*, task};
use async_std::prelude::*;
async fn process(stream: TcpStream) -> io::Result<()> {
println!("Accepted from: {}", stream.peer_addr()?);

@ -14,7 +14,9 @@
#![feature(async_await)]
use async_std::{io, net::UdpSocket, task};
use async_std::io;
use async_std::net::UdpSocket;
use async_std::task;
fn main() -> io::Result<()> {
task::block_on(async {

@ -8,7 +8,9 @@
#![feature(async_await)]
use async_std::{io, net::UdpSocket, task};
use async_std::io;
use async_std::net::UdpSocket;
use async_std::task;
fn main() -> io::Result<()> {
task::block_on(async {

@ -77,7 +77,8 @@ impl DirEntry {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs, prelude::*};
/// use async_std::fs;
/// use async_std::prelude::*;
///
/// let mut dir = fs::read_dir(".").await?;
///
@ -102,7 +103,8 @@ impl DirEntry {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs, prelude::*};
/// use async_std::fs;
/// use async_std::prelude::*;
///
/// let mut dir = fs::read_dir(".").await?;
///
@ -155,7 +157,8 @@ impl DirEntry {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs, prelude::*};
/// use async_std::fs;
/// use async_Std::prelude::*;
///
/// let mut dir = fs::read_dir(".").await?;
///
@ -206,7 +209,8 @@ impl DirEntry {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs, prelude::*};
/// use async_std::fs;
/// use async_std::prelude::*;
///
/// let mut dir = fs::read_dir(".").await?;
///

@ -1,5 +1,4 @@
use std::fs;
use std::path::Path;
use std::pin::Pin;
use std::sync::Mutex;
@ -34,7 +33,8 @@ use crate::task::{blocking, Context, Poll};
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs, prelude::*};
/// use async_std::fs;
/// use async_std::prelude::*;
///
/// let mut dir = fs::read_dir(".").await?;
///

@ -21,12 +21,13 @@ use crate::task::blocking;
///
/// ```no_run
/// # #![feature(async_await)]
/// use async_std::fs::read_to_string;
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::fs;
///
/// # futures::executor::block_on(async {
/// let contents = read_to_string("a.txt").await?;
/// # std::io::Result::Ok(())
/// # }).unwrap();
/// let contents = fs::read_to_string("a.txt").await?;
/// #
/// # Ok(()) }) }
/// ```
pub async fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
let path = path.as_ref().to_owned();

@ -27,7 +27,6 @@ use crate::task::blocking;
///
/// let mut perm = fs::metadata("a.txt").await?.permissions();
/// perm.set_readonly(true);
///
/// fs::set_permissions("a.txt", perm).await?;
/// #
/// # Ok(()) }) }

@ -5,9 +5,10 @@
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use std::time::Duration;
///
/// use async_std::future::pending;
/// use async_std::prelude::*;
/// use std::time::Duration;
///
/// let dur = Duration::from_secs(1);
/// assert!(pending::<()>().timeout(dur).await.is_err());

@ -49,7 +49,9 @@ pub trait BufRead {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, io::BufReader, prelude::*};
/// use async_std::fs::File;
/// use async_std::io::BufReader;
/// use async_std::prelude::*;
///
/// let mut f = BufReader::new(File::open("a.txt").await?);
///
@ -98,7 +100,9 @@ pub trait BufRead {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, io::BufReader, prelude::*};
/// use async_std::fs::File;
/// use async_std::io::BufReader;
/// use async_std::prelude::*;
///
/// let mut f = BufReader::new(File::open("a.txt").await?);
///
@ -137,7 +141,9 @@ pub trait BufRead {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, io::BufReader, prelude::*};
/// use async_std::fs::File;
/// use async_std::io::BufReader;
/// use async_std::prelude::*;
///
/// let mut f = BufReader::new(File::open("a.txt").await?);
///

@ -31,7 +31,8 @@ use crate::io;
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{io, task};
/// use async_std::io;
/// use async_std::task;
///
/// let mut reader: &[u8] = b"hello";
/// let mut writer = io::stdout();

@ -55,7 +55,8 @@ pub trait Read {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, prelude::*};
/// use async_std::fs::File;
/// use async_std::prelude::*;
///
/// let mut f = File::open("a.txt").await?;
///
@ -104,7 +105,8 @@ pub trait Read {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, prelude::*};
/// use async_std::fs::File;
/// use async_std::prelude::*;
///
/// let mut f = File::open("a.txt").await?;
///
@ -141,7 +143,8 @@ pub trait Read {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, prelude::*};
/// use async_std::fs::File;
/// use async_std::prelude::*;
///
/// let mut f = File::open("a.txt").await?;
///
@ -193,7 +196,8 @@ pub trait Read {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, prelude::*};
/// use async_std::fs::File;
/// use async_std::prelude::*;
///
/// let mut f = File::open("a.txt").await?;
///

@ -47,7 +47,9 @@ pub trait Seek {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, io::SeekFrom, prelude::*};
/// use async_std::fs::File;
/// use async_std::io::SeekFrom;
/// use async_std::prelude::*;
///
/// let mut f = File::open("a.txt").await?;
///

@ -19,7 +19,8 @@ use crate::task::{blocking, Context, Poll};
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{io, prelude::*};
/// use async_std::io;
/// use async_std::prelude::*;
///
/// let mut stderr = io::stderr();
/// stderr.write_all(b"Hello, world!").await?;

@ -93,14 +93,15 @@ impl Stdin {
///
/// ```no_run
/// # #![feature(async_await)]
/// use async_std::io::stdin;
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::io;
///
/// # futures::executor::block_on(async {
/// let stdin = stdin();
/// let stdin = io::stdin();
/// let mut line = String::new();
/// stdin.read_line(&mut line).await?;
/// # std::io::Result::Ok(())
/// # }).unwrap();
/// #
/// # Ok(()) }) }
/// ```
pub async fn read_line(&self, buf: &mut String) -> io::Result<usize> {
future::poll_fn(|cx| {

@ -19,7 +19,8 @@ use crate::task::{blocking, Context, Poll};
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{io, prelude::*};
/// use async_std::io;
/// use async_std::prelude::*;
///
/// let mut stdout = io::stdout();
/// stdout.write_all(b"Hello, world!").await?;

@ -50,7 +50,8 @@ pub trait Write {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, prelude::*};
/// use async_std::fs::File;
/// use async_std::prelude::*;
///
/// let mut f = File::create("a.txt").await?;
///
@ -70,7 +71,8 @@ pub trait Write {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, prelude::*};
/// use async_std::fs::File;
/// use async_std::prelude::*;
///
/// let mut f = File::create("a.txt").await?;
///
@ -115,7 +117,8 @@ pub trait Write {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{fs::File, prelude::*};
/// use async_std::fs::File;
/// use async_std::prelude::*;
///
/// let mut f = File::create("a.txt").await?;
///

@ -33,7 +33,9 @@ use crate::task::{Context, Poll};
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{io, net::TcpListener, prelude::*};
/// use async_std::io;
/// use async_std::net::TcpListener;
/// use async_std::prelude::*;
///
/// let listener = TcpListener::bind("127.0.0.1:8080").await?;
/// let mut incoming = listener.incoming();
@ -173,7 +175,8 @@ impl TcpListener {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{net::TcpListener, prelude::*};
/// use async_std::net::TcpListener;
/// use async_std::prelude::*;
///
/// let listener = TcpListener::bind("127.0.0.1:0").await?;
/// let mut incoming = listener.incoming();

@ -36,7 +36,8 @@ use crate::task::{Context, Poll};
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::{net::TcpStream, prelude::*};
/// use async_std::net::TcpStream;
/// use async_std::prelude::*;
///
/// let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
/// stream.write_all(b"hello world").await?;
@ -340,9 +341,10 @@ impl TcpStream {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::net::TcpStream;
/// use std::net::Shutdown;
///
/// use async_std::net::TcpStream;
///
/// let stream = TcpStream::connect("127.0.0.1:8080").await?;
/// stream.shutdown(Shutdown::Both)?;
/// #

@ -117,9 +117,10 @@ impl UdpSocket {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::net::UdpSocket;
/// use std::net::IpAddr;
///
/// use async_std::net::UdpSocket;
///
/// let socket = UdpSocket::bind("127.0.0.1:0").await?;
/// let addr = socket.local_addr()?;
/// #
@ -446,9 +447,10 @@ impl UdpSocket {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::net::UdpSocket;
/// use std::net::Ipv4Addr;
///
/// use async_std::net::UdpSocket;
///
/// let interface = Ipv4Addr::new(0, 0, 0, 0);
/// let mdns_addr = Ipv4Addr::new(224, 0, 0, 123);
///
@ -475,9 +477,10 @@ impl UdpSocket {
/// # #![feature(async_await)]
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::net::UdpSocket;
/// use std::net::{Ipv6Addr, SocketAddr};
///
/// use async_std::net::UdpSocket;
///
/// let socket_addr = SocketAddr::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0).into(), 0);
/// let mdns_addr = Ipv6Addr::new(0xFF02, 0, 0, 0, 0, 0, 0, 0x0123) ;
/// let socket = UdpSocket::bind(&socket_addr).await?;

@ -65,9 +65,10 @@ cfg_if! {
/// With a pathname:
///
/// ```no_run
/// use async_std::os::unix::net::UnixListener;
/// use std::path::Path;
///
/// use async_std::os::unix::net::UnixListener;
///
/// let socket = UnixListener::bind("/tmp/socket").await?;
/// let addr = socket.local_addr()?;
/// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/socket")));

@ -37,4 +37,6 @@ pub use crate::io::Write as _;
#[doc(no_inline)]
pub use crate::stream::Stream;
#[doc(no_inline)]
pub use crate::task_local;
#[doc(no_inline)]
pub use crate::time::Timeout as _;

@ -11,7 +11,8 @@ use crate::task::{Context, Poll};
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::{prelude::*, stream};
/// use async_std::prelude::*;
/// use async_std::stream;
///
/// let mut s = stream::empty::<i32>();
///

@ -10,7 +10,8 @@
//! # #![feature(async_await)]
//! # fn main() { async_std::task::block_on(async {
//! #
//! use async_std::{prelude::*, stream};
//! use async_std::prelude::*;
//! use async_std::stream;
//!
//! let mut s = stream::repeat(9).take(3);
//!

@ -10,7 +10,8 @@ use crate::task::{Context, Poll};
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::{prelude::*, stream};
/// use async_std::prelude::*;
/// use async_std::stream;
///
/// let mut s = stream::once(7);
///

@ -10,7 +10,8 @@ use crate::task::{Context, Poll};
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::{prelude::*, stream};
/// use async_std::prelude::*;
/// use async_std::stream;
///
/// let mut s = stream::repeat(7);
///

@ -10,7 +10,8 @@
//! # #![feature(async_await)]
//! # fn main() { async_std::task::block_on(async {
//! #
//! use async_std::{prelude::*, stream};
//! use async_std::prelude::*;
//! use async_std::stream;
//!
//! let mut s = stream::repeat(9).take(3);
//!
@ -71,7 +72,8 @@ pub trait Stream {
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::{prelude::*, stream};
/// use async_std::prelude::*;
/// use async_std::stream;
///
/// let mut s = stream::once(7);
///
@ -92,7 +94,8 @@ pub trait Stream {
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::{prelude::*, stream};
/// use async_std::prelude::*;
/// use async_std::stream;
///
/// let mut s = stream::repeat(9).take(3);
///

@ -12,9 +12,11 @@
//! # #![feature(async_await)]
//! # fn main() { async_std::task::block_on(async {
//! #
//! use async_std::{sync::Mutex, task};
//! use std::sync::Arc;
//!
//! use async_std::sync::Mutex;
//! use async_std::task;
//!
//! let m1 = Arc::new(Mutex::new(0));
//! let m2 = m1.clone();
//!

@ -27,9 +27,11 @@ const BLOCKED: usize = 1 << 1;
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::{sync::Mutex, task};
/// use std::sync::Arc;
///
/// use async_std::sync::Mutex;
/// use async_std::task;
///
/// let m = Arc::new(Mutex::new(0));
/// let mut tasks = vec![];
///
@ -84,9 +86,11 @@ impl<T> Mutex<T> {
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::{sync::Mutex, task};
/// use std::sync::Arc;
///
/// use async_std::sync::Mutex;
/// use async_std::task;
///
/// let m1 = Arc::new(Mutex::new(10));
/// let m2 = m1.clone();
///
@ -197,9 +201,11 @@ impl<T> Mutex<T> {
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::{sync::Mutex, task};
/// use std::sync::Arc;
///
/// use async_std::sync::Mutex;
/// use async_std::task;
///
/// let m1 = Arc::new(Mutex::new(10));
/// let m2 = m1.clone();
///
@ -229,7 +235,6 @@ impl<T> Mutex<T> {
/// # Examples
///
/// ```
/// # #![feature(async_await)]
/// use async_std::sync::Mutex;
///
/// let mutex = Mutex::new(10);

@ -21,9 +21,12 @@ use super::pool;
///
/// ```
/// # #![feature(async_await)]
/// use async_std::{task, task_local};
/// #
/// use std::cell::Cell;
///
/// use async_std::task;
/// use async_std::prelude::*;
///
/// task_local! {
/// static VAL: Cell<u32> = Cell::new(5);
/// }
@ -90,9 +93,12 @@ impl<T: Send + 'static> LocalKey<T> {
///
/// ```
/// # #![feature(async_await)]
/// use async_std::{task, task_local};
/// #
/// use std::cell::Cell;
///
/// use async_std::task;
/// use async_std::prelude::*;
///
/// task_local! {
/// static NUMBER: Cell<u32> = Cell::new(5);
/// }
@ -127,9 +133,12 @@ impl<T: Send + 'static> LocalKey<T> {
///
/// ```
/// # #![feature(async_await)]
/// use async_std::{task, task_local};
/// #
/// use std::cell::Cell;
///
/// use async_std::task;
/// use async_std::prelude::*;
///
/// task_local! {
/// static VAL: Cell<u32> = Cell::new(5);
/// }

@ -32,9 +32,9 @@ use crate::io;
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::task::current;
/// use async_std::task;
///
/// println!("The name of this task is {:?}", current().name());
/// println!("The name of this task is {:?}", task::current().name());
/// #
/// # }) }
/// ```

@ -18,9 +18,10 @@ use crate::time::Timeout;
/// # #![feature(async_await)]
/// # fn main() { async_std::task::block_on(async {
/// #
/// use async_std::task;
/// use std::time::Duration;
///
/// use async_std::task;
///
/// task::sleep(Duration::from_secs(1)).await;
/// #
/// # }) }

Loading…
Cancel
Save