From f55b6f681c0d0ff8bdc640ba23300fa7282278c9 Mon Sep 17 00:00:00 2001
From: Dmitry <b4tm4n@mail.ru>
Date: Sun, 6 Aug 2023 16:58:43 +0300
Subject: [PATCH] move str_err to util.rs

---
 lib/src/async_db.rs | 15 +--------------
 lib/src/db.rs       | 15 +--------------
 lib/src/util.rs     | 14 ++++++++++++++
 3 files changed, 16 insertions(+), 28 deletions(-)
 create mode 100644 lib/src/util.rs

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::<LSize>();
 const BINCODE_CFG: bincode::config::Configuration = bincode::config::standard();
 
-trait ErrorToString {
-    type Output;
-    fn str_err(self) -> std::result::Result<Self::Output, String>;
-}
-
-impl<T, E> ErrorToString for std::result::Result<T, E>
-where
-    E: std::error::Error,
-{
-    type Output = T;
-    fn str_err(self) -> std::result::Result<Self::Output, String> {
-        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::<LSize>();
 const BINCODE_CFG: bincode::config::Configuration = bincode::config::standard();
 
-trait ErrorToString {
-    type Output;
-    fn str_err(self) -> std::result::Result<Self::Output, String>;
-}
-
-impl<T, E> ErrorToString for std::result::Result<T, E>
-where
-    E: std::error::Error,
-{
-    type Output = T;
-    fn str_err(self) -> std::result::Result<Self::Output, String> {
-        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<Self::Output, String>;
+}
+
+impl<T, E> ErrorToString for std::result::Result<T, E>
+where
+    E: std::error::Error,
+{
+    type Output = T;
+    fn str_err(self) -> std::result::Result<Self::Output, String> {
+        self.map_err(|e| e.to_string())
+    }
+}