Hi all,
I'm playing around with tokio/streams/futures/async/await trying to learn how to work with them all.
Got stuck trying to do what I though would be a simple thing. I have a stream of some vectors and want to write these vectors from stream to a file, something like below:
// [dependencies]
// futures-preview = {version = "0.3.0-alpha.19", features = [ "async-await"] }
// tokio = "0.2.0-alpha.6"
use futures::{future, future::FutureExt, stream, stream::StreamExt};
use tokio::io::AsyncWriteExt;
#[tokio::main]
async fn main() {
let mut file = tokio::fs::OpenOptions::new()
.write(true)
.create(true)
.open("some_file")
.await
.unwrap();
let mut stream = stream::repeat::<Vec<u8>>(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
stream
.for_each(move |v| file.write_all(&v).then(|_| future::ready(())))
.await;
}
However compiling this results in:
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements...
...and some further description of the error which I don't really understand:
note: first, the lifetime cannot outlive the lifetime '_ as defined on the body ...
note:...so that closure can access `file`
...and more
Maybe something needs pinning, maybe it's due to playing with bleeding edge stuff?
Anyhow! I would be very happy if someone could explain how to solve this or point me in the direction of some good docs
Thanks in advance!