diff options
Diffstat (limited to 'src/facility/i3.rs')
| -rw-r--r-- | src/facility/i3.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/facility/i3.rs b/src/facility/i3.rs index 53258f8..4dd4a87 100644 --- a/src/facility/i3.rs +++ b/src/facility/i3.rs @@ -531,7 +531,7 @@ fn parse_success_object(json: &[u8]) -> Result<bool> { } -pub fn parse_change_string(json: &[u8]) -> Result<String> { +fn parse_top_level_key_string(json: &[u8], expected_key: &str) -> Result<String> { let mut parser = SliceJsonParser::new(json); if let JsonEvent::StartObject = parser.parse_next()? { } else { @@ -539,7 +539,7 @@ pub fn parse_change_string(json: &[u8]) -> Result<String> { } if let JsonEvent::ObjectKey(key) = parser.parse_next()? { - if key == "change" { + if key == expected_key { if let JsonEvent::String(result) = parser.parse_next()? { /* That's our answer; exit early. */ return Ok(result.into_owned()); @@ -547,10 +547,21 @@ pub fn parse_change_string(json: &[u8]) -> Result<String> { return Err(Error::custom("Reading i3 JSON, expected string.")); } } else { - return Err(Error::custom("Reading i3 JSON, expected \"change\" key.")); + return Err(Error::custom(&format!("Reading i3 JSON, expected {:?} key.", + expected_key))); } } else { return Err(Error::custom("Reading i3 JSON, expected object key.")); } } + +pub fn parse_change_string(json: &[u8]) -> Result<String> { + parse_top_level_key_string(json, "change") +} + + +pub fn parse_name_string(json: &[u8]) -> Result<String> { + parse_top_level_key_string(json, "name") +} + |