diff --git a/lib/src/async_db.rs b/lib/src/async_db.rs index 5c44eeb..d5f6801 100644 --- a/lib/src/async_db.rs +++ b/lib/src/async_db.rs @@ -22,20 +22,7 @@ type LSize = u32; const LEN_SIZE: usize = std::mem::size_of::(); const BINCODE_CFG: bincode::config::Configuration = bincode::config::standard(); -trait ErrorToString { - type Output; - fn str_err(self) -> std::result::Result; -} - -impl ErrorToString for std::result::Result -where - E: std::error::Error, -{ - type Output = T; - fn str_err(self) -> std::result::Result { - self.map_err(|e| e.to_string()) - } -} +use crate::util::ErrorToString; pub struct WriterOpts { pub compress_lvl: Level, diff --git a/lib/src/db.rs b/lib/src/db.rs index f97e09d..7993003 100644 --- a/lib/src/db.rs +++ b/lib/src/db.rs @@ -12,20 +12,7 @@ type LSize = u32; const LEN_SIZE: usize = std::mem::size_of::(); const BINCODE_CFG: bincode::config::Configuration = bincode::config::standard(); -trait ErrorToString { - type Output; - fn str_err(self) -> std::result::Result; -} - -impl ErrorToString for std::result::Result -where - E: std::error::Error, -{ - type Output = T; - fn str_err(self) -> std::result::Result { - self.map_err(|e| e.to_string()) - } -} +use crate::util::ErrorToString; pub struct WriterOpts { pub compress_lvl: i32, diff --git a/lib/src/util.rs b/lib/src/util.rs new file mode 100644 index 0000000..e33f587 --- /dev/null +++ b/lib/src/util.rs @@ -0,0 +1,14 @@ +pub trait ErrorToString { + type Output; + fn str_err(self) -> std::result::Result; +} + +impl ErrorToString for std::result::Result +where + E: std::error::Error, +{ + type Output = T; + fn str_err(self) -> std::result::Result { + self.map_err(|e| e.to_string()) + } +}