Refactorings
This commit is contained in:
parent
5a16bc7ba0
commit
35e4332e2f
2 changed files with 11 additions and 13 deletions
18
src/main.rs
18
src/main.rs
|
@ -94,14 +94,13 @@ fn main() {
|
||||||
// meminfo
|
// meminfo
|
||||||
{
|
{
|
||||||
let meminfo_result = proc::get_meminfo();
|
let meminfo_result = proc::get_meminfo();
|
||||||
let meminfo_string: String;
|
let meminfo_string: String = if let Err(e) = meminfo_result {
|
||||||
if let Err(e) = meminfo_result {
|
|
||||||
let mut stderr_handle = io::stderr().lock();
|
let mut stderr_handle = io::stderr().lock();
|
||||||
stderr_handle.write_all(format!("{}\n", e).as_bytes()).ok();
|
stderr_handle.write_all(format!("{}\n", e).as_bytes()).ok();
|
||||||
meminfo_string = String::from("MEMINFO ERROR");
|
String::from("MEMINFO ERROR")
|
||||||
} else {
|
} else {
|
||||||
meminfo_string = meminfo_result.unwrap();
|
meminfo_result.unwrap()
|
||||||
}
|
};
|
||||||
let meminfo_obj = SwaybarObject::from_string(meminfo_string);
|
let meminfo_obj = SwaybarObject::from_string(meminfo_string);
|
||||||
array.push_object(meminfo_obj);
|
array.push_object(meminfo_obj);
|
||||||
}
|
}
|
||||||
|
@ -109,14 +108,13 @@ fn main() {
|
||||||
// loadavg
|
// loadavg
|
||||||
{
|
{
|
||||||
let loadavg_result = proc::get_loadavg();
|
let loadavg_result = proc::get_loadavg();
|
||||||
let loadavg_string: String;
|
let loadavg_string: String = if let Err(e) = loadavg_result {
|
||||||
if let Err(e) = loadavg_result {
|
|
||||||
let mut stderr_handle = io::stderr().lock();
|
let mut stderr_handle = io::stderr().lock();
|
||||||
stderr_handle.write_all(format!("{}\n", e).as_bytes()).ok();
|
stderr_handle.write_all(format!("{}\n", e).as_bytes()).ok();
|
||||||
loadavg_string = String::from("LOADAVG ERROR");
|
String::from("LOADAVG ERROR")
|
||||||
} else {
|
} else {
|
||||||
loadavg_string = loadavg_result.unwrap();
|
loadavg_result.unwrap()
|
||||||
}
|
};
|
||||||
let loadavg_obj = SwaybarObject::from_string(loadavg_string);
|
let loadavg_obj = SwaybarObject::from_string(loadavg_string);
|
||||||
array.push_object(loadavg_obj);
|
array.push_object(loadavg_obj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ impl std::error::Error for Error {
|
||||||
Error::IO(e) => e.source(),
|
Error::IO(e) => e.source(),
|
||||||
Error::ParseInt(e) => e.source(),
|
Error::ParseInt(e) => e.source(),
|
||||||
Error::Format(e) => e.source(),
|
Error::Format(e) => e.source(),
|
||||||
_ => None,
|
Error::Generic(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,10 +83,10 @@ impl NetInfo {
|
||||||
netdev_file.read_to_string(&mut netdev_string)?;
|
netdev_file.read_to_string(&mut netdev_string)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut dev_line: Option<String> = None;
|
let mut dev_line: Option<&str> = None;
|
||||||
for line in netdev_string.lines() {
|
for line in netdev_string.lines() {
|
||||||
if line.starts_with(&self.dev_name) {
|
if line.starts_with(&self.dev_name) {
|
||||||
dev_line = Some(line.to_owned());
|
dev_line = Some(line);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue