smol/examples/read-file.rs

19 lines
419 B
Rust
Raw Normal View History

2020-04-21 15:51:07 +00:00
// TODO: document
2020-02-09 14:32:44 +00:00
//! Prints a file given as an argument to stdout.
2020-04-20 15:45:14 +00:00
use std::env;
2020-03-31 16:04:16 +00:00
use std::fs::File;
use std::io;
2020-02-09 14:32:44 +00:00
fn main() -> io::Result<()> {
let path = env::args().nth(1).expect("missing path argument");
smol::run(async {
2020-03-31 16:04:16 +00:00
let file = smol::reader(File::open(path)?);
let mut stdout = smol::writer(io::stdout());
futures::io::copy(file, &mut stdout).await?;
2020-02-09 14:32:44 +00:00
Ok(())
})
}