From 008077bf0d791c2c7d6fa218a96e398ba0758ff8 Mon Sep 17 00:00:00 2001 From: Marko Grujic Date: Fri, 23 Aug 2024 17:01:11 +0200 Subject: [PATCH] Make Add::get_json_stats public --- crates/core/src/protocol/mod.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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() } }