#read-write #async-write #read #write #async-read #future #async-io

nightly 伪异步-io

简单的(伪)异步Read和Write包装器

1个不稳定版本

0.1.0 2019年3月5日

#34#async-write

MIT/Apache

7KB
60

伪异步-io

简单的(伪)AsyncRead/AsyncWrite围绕Read和Write特性进行包装。

适用于futures-0.3;需要nightly rust。

#![feature(async_await, await_macro, futures_api)]

use std::io::Cursor;
use futures::{
    io::AsyncReadExt,
    io::AsyncWriteExt,
	io::Error,
    future::FutureExt,
    executor::block_on,
};
use pseudo_async_io;

async fn do_some_io() -> Result<Vec<u8>, Error> {
	let mut w = pseudo_async_io::wrap(Cursor::new(vec![1; 6]));
	await!(w.write_all(&[1, 2, 3]))?;

	let mut tmp = vec![0; 4];
	await!(w.read(&mut tmp))?;
	Ok(tmp)
}

依赖

~1MB
~17K SLoC