blob: fdc3bed073a610102ae6804b682a8d8fcac81ef0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
use anyhow::Context as _;
use std::io::BufRead as _;
pub fn read_ints(filename: &str) -> anyhow::Result<Vec<i32>> {
let f = std::fs::File::open(filename)
.with_context(|| format!("couldn't find data file {}", filename))?;
let f = std::io::BufReader::new(f);
let ints: anyhow::Result<Vec<i32>> = f
.lines()
.map(|l| {
l.context("failed to read a line")?
.parse()
.context("failed to parse line into an integer")
})
.collect();
ints
}
|