Skip to content

Instantly share code, notes, and snippets.

@73nko
Created November 28, 2021 11:04
Show Gist options
  • Save 73nko/ecb5ddce2a04cf3aa05778013a6c95b9 to your computer and use it in GitHub Desktop.
Save 73nko/ecb5ddce2a04cf3aa05778013a6c95b9 to your computer and use it in GitHub Desktop.
Read Lines in a File Rust
let mut items: Vec<usize> = include_str!("../input.txt")
.lines()
.map(|i| i.parse().unwrap())
.collect();
// Or
fn read_ints(path: &str) -> Vec<i32> {
let mut out: Vec<i32> = Vec::new();
let lines = util::read_lines(path).unwrap();
for line in lines {
let num = line.unwrap().parse::<i32>().unwrap();
out.push(num);
}
out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment