Refactor error handling in proc.rs
This commit is contained in:
parent
35e4332e2f
commit
ed8d0b3f31
1 changed files with 2 additions and 7 deletions
|
@ -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"))?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue