Another day, another basic Rust thing that I can't figure out on my own. So sorry to keep posting here so frequently.
In Cargo.toml
:
async-std = "1.9.0"
futures = "0.3.12"
In src/main.rs
:
use async_std::fs::{File};
use async_std::io::{BufReader, Error, Result};
use async_std::prelude::*;
async fn sum_file(file_path: &str) -> Result<i32, io::Error> {
let f = File::open(path)?;
let reader = BufReader::new(f);
let mut sum = 0.0;
for line in reader.lines() {
let n : f64 = line.parse()?;
println!("n = {}", n);
sum += n;
}
Ok(sum)
}
#[async_std::main]
async fn main() {
match sum_file("./numbers.txt").await {
Ok(sum) => println!("sum = {}", sum),
Err(e) => eprintln!("error = {}", e)
}
}
Clippy output:
18 | #[async_std::main] │https://eslint.org has 26 img tags
| ^^^^ could not find `main` in `async_std`
followed by many more errors. But why do I get this first error?