I thought I understood that every async function returns a Future
. So I don't understand this error message: " std::result::Result<std::fs::File, std::io::Error>
is not a future
the trait futures::Future
is not implemented for std::result::Result<std::fs::File, std::io::Error>
required by futures::Future::poll
rustcE0277".
I get this error for the File::open
line ad the stream.next
line in the code snippet below.
use std::{
fs::File,
io::{BufReader, Result},
task,
};
// This is needed to call the "lines" method on a std::io::BufReader.
use std::io::prelude::*;
async fn sum_file_async(file_path: &str) -> Result<f64> {
let f = File::open(file_path).await?;
let reader = BufReader::new(f);
let mut sum = 0.0;
let mut stream = reader.lines();
while let Some(Ok(line)) = stream.next().await {
if let Ok(n) = line.parse::<f64>() {
println!("{}", n);
sum += n;
}
}
Ok(sum)
}
All I have to do to get rid of the error is change the first line to use async_std::{
. But when I look at the documentation for the open function in std::fs::File
and async_std::fs::File
I don't see any difference that would explain why I get the error.
Basically I'm trying to learn what I can do with async/await using only what is in std
.