dmesg: use functional approach to read lines.
This commit is contained in:
@ -92,18 +92,12 @@ impl Dmesg<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_lines_from_kmsg_file(&self) -> UResult<Vec<String>> {
|
fn read_lines_from_kmsg_file(&self) -> UResult<Vec<String>> {
|
||||||
let mut lines = vec![];
|
|
||||||
let mut line = vec![];
|
|
||||||
let kmsg_bytes = fs::read(self.kmsg_file)
|
let kmsg_bytes = fs::read(self.kmsg_file)
|
||||||
.map_err_context(|| format!("cannot open {}", self.kmsg_file))?;
|
.map_err_context(|| format!("cannot open {}", self.kmsg_file))?;
|
||||||
for byte in kmsg_bytes {
|
let lines = kmsg_bytes
|
||||||
if byte == 0 {
|
.split(|&byte| byte == 0)
|
||||||
lines.push(String::from_utf8_lossy(&line).to_string());
|
.map(|line| String::from_utf8_lossy(line).to_string())
|
||||||
line.clear();
|
.collect();
|
||||||
} else {
|
|
||||||
line.push(byte);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(lines)
|
Ok(lines)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user