diff options
author | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2017-06-17 22:31:27 -0400 |
---|---|---|
committer | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2017-06-17 22:31:27 -0400 |
commit | 76b90acb735d3ed2b3052abc1d2403287af83619 (patch) | |
tree | 857de2ebee3d2b6ea802aa1ef249ea34bb0e0908 /src/systemd | |
parent | 1e5f237c20310cbf6ace17b6a7b05298429aca46 (diff) |
rustfmt: Reformatted all the code.
Diffstat (limited to 'src/systemd')
-rw-r--r-- | src/systemd/journal.rs | 5 | ||||
-rw-r--r-- | src/systemd/unit.rs | 42 |
2 files changed, 28 insertions, 19 deletions
diff --git a/src/systemd/journal.rs b/src/systemd/journal.rs index 86791ab..fa01c49 100644 --- a/src/systemd/journal.rs +++ b/src/systemd/journal.rs @@ -3,8 +3,7 @@ use std::io; pub fn get_log(unit: &str, lines: i32) -> io::Result<String> { let status = try!(Command::new("journalctl") - .args(&["-u", unit, - "-n", &lines.to_string()]) - .output()); + .args(&["-u", unit, "-n", &lines.to_string()]) + .output()); Ok(String::from_utf8_lossy(&status.stdout).into_owned()) } diff --git a/src/systemd/unit.rs b/src/systemd/unit.rs index 116ffdb..d43324a 100644 --- a/src/systemd/unit.rs +++ b/src/systemd/unit.rs @@ -14,31 +14,40 @@ pub struct Unit { pub fn parse_key_value(line: &str) -> Option<(String, String)> { let pos = line.find('='); pos.map(|pos| { - let (k, v) = line.split_at(pos); - (k.to_owned(), v[1..].to_owned()) - }) + let (k, v) = line.split_at(pos); + (k.to_owned(), v[1..].to_owned()) + }) } #[test] fn test_parse_key_value() { assert_eq!(None, parse_key_value("ab")); - assert_eq!(Some(("a".to_owned(), "b".to_owned())), parse_key_value("a=b")); - assert_eq!(Some(("a".to_owned(), "b=c".to_owned())), parse_key_value("a=b=c")); + assert_eq!(Some(("a".to_owned(), "b".to_owned())), + parse_key_value("a=b")); + assert_eq!(Some(("a".to_owned(), "b=c".to_owned())), + parse_key_value("a=b=c")); } fn make_unit(info: HashMap<String, String>) -> Option<Unit> { fn from_id(id: &str) -> Option<String> { id.rsplit('.').next().map(|t| t.to_owned()) }; - fn cloned(s: &String) -> String { s.clone() } + fn cloned(s: &String) -> String { + s.clone() + } let id = info.get("Id").map(cloned); let type_ = id.as_ref().and_then(|id| from_id(&id)); let active_state = info.get("ActiveState").map(cloned); let sub_state = info.get("SubState").map(cloned); - + if let (Some(id), Some(type_), Some(active_state), Some(sub_state)) = (id, type_, active_state, sub_state) { - Some(Unit { name: id, type_: type_, active_state: active_state, sub_state: sub_state }) + Some(Unit { + name: id, + type_: type_, + active_state: active_state, + sub_state: sub_state, + }) } else { None } @@ -47,13 +56,13 @@ fn make_unit(info: HashMap<String, String>) -> Option<Unit> { #[test] fn test_make_unit() { let s = |s: &str| -> String { s.to_owned() }; - let info = [ - (s("Id"), s("Test.service")), - (s("ActiveState"), s("active")), - (s("SubState"), s("running")), - ] - .iter().cloned().collect::<HashMap<String, String>>(); - let actual = make_unit(info).unwrap();; + let info = [(s("Id"), s("Test.service")), + (s("ActiveState"), s("active")), + (s("SubState"), s("running"))] + .iter() + .cloned() + .collect::<HashMap<String, String>>(); + let actual = make_unit(info).unwrap(); assert_eq!(s("Test.service"), actual.name); let info = HashMap::new(); @@ -63,7 +72,8 @@ fn test_make_unit() { pub fn get_units(filter: &str) -> io::Result<Vec<Unit>> { let mut units = Vec::new(); let status = try!(Command::new("systemctl") - .args(&["show", filter]).output()); + .args(&["show", filter]) + .output()); let mut unit_info = HashMap::new(); for line in String::from_utf8_lossy(&status.stdout).split('\n') { |