#![allow(unused)]
fn main() {
use std::fs::File;
fn read_username_from_file() -> Result<String, io::Error> {
let f = File::open("helo.txt");
let mut f = match f {
Ok(file) => file,
// Return early if there's an error
Err(e) => return Err(e),
};
let mut s = String::new();
// Because last call it returns <String, io::Error>
match f.read_to_string(&mut s) {
Ok(_) => Ok(s),
Err(e) => Err(e),
}
}
}
#![allow(unused)]
fn main() {
use std::io;
use std::io::Read;
use std::fs::File;
fn read_username_from_file() -> Result<String, io::Error> {
let mut f = File::open("hello.txt")?;
let mut s = String::new();
f.read_to_string(&mut s)?;
Ok(s)
}
}