move str_err to util.rs
This commit is contained in:
parent
c0193e4f74
commit
f55b6f681c
@ -22,20 +22,7 @@ type LSize = u32;
|
|||||||
const LEN_SIZE: usize = std::mem::size_of::<LSize>();
|
const LEN_SIZE: usize = std::mem::size_of::<LSize>();
|
||||||
const BINCODE_CFG: bincode::config::Configuration = bincode::config::standard();
|
const BINCODE_CFG: bincode::config::Configuration = bincode::config::standard();
|
||||||
|
|
||||||
trait ErrorToString {
|
use crate::util::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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WriterOpts {
|
pub struct WriterOpts {
|
||||||
pub compress_lvl: Level,
|
pub compress_lvl: Level,
|
||||||
|
@ -12,20 +12,7 @@ type LSize = u32;
|
|||||||
const LEN_SIZE: usize = std::mem::size_of::<LSize>();
|
const LEN_SIZE: usize = std::mem::size_of::<LSize>();
|
||||||
const BINCODE_CFG: bincode::config::Configuration = bincode::config::standard();
|
const BINCODE_CFG: bincode::config::Configuration = bincode::config::standard();
|
||||||
|
|
||||||
trait ErrorToString {
|
use crate::util::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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WriterOpts {
|
pub struct WriterOpts {
|
||||||
pub compress_lvl: i32,
|
pub compress_lvl: i32,
|
||||||
|
14
lib/src/util.rs
Normal file
14
lib/src/util.rs
Normal file
@ -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())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user