Existing answers I\'ve found are all based on from_str
(such as Reading in user input from console once efficiently), but apparently from_str(x)
h
I would definitely use the file system Rust-Lang provides std::fs
(See more here: https://doc.rust-lang.org/stable/std/fs/) But more particularly https://doc.rust-lang.org/stable/std/fs/fn.read_to_string.html
Let's say you just want to read input of a text file, try this :
use std::fs
or
use std::fs::read_to_string
fn main() {
println!("{}", fs::read_to_string("input.txt"));
}