diff --git a/crates/core/src/protocol/mod.rs b/crates/core/src/protocol/mod.rs index 8c857f92de..f4f6e2760b 100644 --- a/crates/core/src/protocol/mod.rs +++ b/crates/core/src/protocol/mod.rs @@ -259,17 +259,11 @@ impl Add { /// Returns the serde_json representation of stats contained in the action if present. /// Since stats are defined as optional in the protocol, this may be None. - fn get_json_stats(&self) -> Result, serde_json::error::Error> { - let ps: Result, serde_json::error::Error> = self - .stats + pub fn get_json_stats(&self) -> Result, serde_json::error::Error> { + self.stats .as_ref() - .map_or(Ok(None), |s| serde_json::from_str(s)); - - match ps { - Ok(Some(mut partial)) => Ok(Some(partial.as_stats())), - Ok(None) => Ok(None), - Err(e) => Err(e), - } + .map(|stats| serde_json::from_str(stats).map(|mut ps: PartialStats| ps.as_stats())) + .transpose() } }