Refactor error handling in proc.rs

This commit is contained in:
Stephen Seo 2022-07-10 13:13:57 +09:00
parent 35e4332e2f
commit ed8d0b3f31

View file

@ -1,6 +1,5 @@
use std::fmt::Write; use std::fmt::Write;
use std::fs::File; use std::fs::File;
use std::io;
use std::io::prelude::*; use std::io::prelude::*;
#[derive(Debug)] #[derive(Debug)]
@ -153,17 +152,13 @@ pub fn get_meminfo() -> Result<String, Error> {
.split_whitespace() .split_whitespace()
.map(|s| s.to_owned()) .map(|s| s.to_owned())
.collect::<Vec<String>>(); .collect::<Vec<String>>();
total = line_parts[1] total = line_parts[1].parse()?;
.parse()
.map_err(|_| io::Error::new(io::ErrorKind::Other, "MemTotal: parse error"))?;
} else if line.starts_with("MemAvailable:") { } else if line.starts_with("MemAvailable:") {
let line_parts = line let line_parts = line
.split_whitespace() .split_whitespace()
.map(|s| s.to_owned()) .map(|s| s.to_owned())
.collect::<Vec<String>>(); .collect::<Vec<String>>();
available = line_parts[1] available = line_parts[1].parse()?;
.parse()
.map_err(|_| io::Error::new(io::ErrorKind::Other, "MemAvailable: parse error"))?;
} }
} }