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()) +}