Hi Folks,
I am new to Rust and am trying to figure out Result return types. I am trying to extract the error code returned by fn read_username_from_file -> Result<String, io::Error>. The compiler reports that the Result type is not indexed. If someone could point me in to a solution, I would appreciate it.
Thanks
use std::fs::File;
use std::io;
use std::io::Read;
fn main() {
println!("{}", read_username_from_file()[1]);
}
fn read_username_from_file() -> Result<String, io::Error> {
let f = File::open("hello.txt");
let mut f = match f {
Ok(file) => file,
Err(e) => return Err(e),
};
let mut s = String::new();
match f.read_to_string(&mut s) {
Ok(_) => Ok(s),
Err(e) => Err(e),
}
}```