From 5aef7f81a6ac8b490d4c10e92d894d26f6d0efd1 Mon Sep 17 00:00:00 2001 From: Fangdun Tsai Date: Tue, 2 Jan 2024 15:59:48 +0800 Subject: [PATCH] refactor: AFIT & RPITIT --- sessions-core/src/session.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sessions-core/src/session.rs b/sessions-core/src/session.rs index 14b42f8..21d5653 100644 --- a/sessions-core/src/session.rs +++ b/sessions-core/src/session.rs @@ -46,7 +46,7 @@ impl Session { match self .lock_data() .read() - .map_err(|e| Error::new(ErrorKind::Other, e.to_string()))? + .map_err(into_io_error)? .get(key) .cloned() { @@ -70,7 +70,7 @@ impl Session { } d.insert( key.into(), - serde_json::to_value(val).map_err(|e| Error::new(ErrorKind::Other, e))?, + serde_json::to_value(val).map_err(into_io_error)?, ); } } @@ -141,7 +141,7 @@ impl Session { pub fn data(&self) -> Result { self.lock_data() .read() - .map_err(|e| Error::new(ErrorKind::Other, e.to_string())) + .map_err(into_io_error) .map(|d| d.clone()) } } @@ -151,3 +151,8 @@ impl fmt::Debug for Session { self.state.fmt(f) } } + +#[inline] +fn into_io_error(e: E) -> Error { + Error::new(ErrorKind::Other, e.to_string()) +}