Helper functions

Additionally, just like std, the tokio::io module contains a number of helpful utility functions as well as APIs for working with standard input, standard output and standard error. For example, tokio::io::copy asynchronously copies the entire contents of a reader into a writer.

1. use tokio::fs::File;
2. use tokio::io;

4. #[tokio::main]
5. async fn main() -> io::Result<()> {
6. let mut reader: &[u8] = b"hello";
7. let mut file = File::create("foo.txt").await?;

9. io::copy(&mut reader, &mut file).await?;
10. Ok(())
11. }

Note that this uses the fact that byte arrays also implement AsyncRead.