read from file in rust
1. advent of code go-to
use std::fs;
use std::path::Path;
fn parse_input(fname: &str){
let root_path = Path::new("/home/path/to/dir");
let fpath = root_path.join(fname);
let string = fs::read_to_string(fpath).expect("couldn't find file");
}
From here.
2. beware of dropping temporary variable
- See here