diff --git a/heed-traits/src/lib.rs b/heed-traits/src/lib.rs index f1eb67a4..0f80d8c3 100644 --- a/heed-traits/src/lib.rs +++ b/heed-traits/src/lib.rs @@ -1,19 +1,17 @@ use std::borrow::Cow; -use std::error::Error as StdError; - -/// A boxed `Send + Sync + 'static` error. -pub type BoxedError = Box; /// A trait that represents an encoding structure. pub trait BytesEncode<'a> { type EItem: ?Sized + 'a; + type Err; - fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError>; + fn bytes_encode(item: &'a Self::EItem) -> Result, Self::Err>; } /// A trait that represents a decoding structure. pub trait BytesDecode<'a> { type DItem: 'a; + type Err; - fn bytes_decode(bytes: &'a [u8]) -> Result; + fn bytes_decode(bytes: &'a [u8]) -> Result; } diff --git a/heed-types/src/cow_slice.rs b/heed-types/src/cow_slice.rs index 48f30b19..1891947e 100644 --- a/heed-types/src/cow_slice.rs +++ b/heed-types/src/cow_slice.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use bytemuck::{pod_collect_to_vec, try_cast_slice, AnyBitPattern, NoUninit, PodCastError}; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use heed_traits::{BytesDecode, BytesEncode}; /// Describes a slice that must be [memory aligned] and /// will be reallocated if it is not. @@ -22,20 +22,22 @@ pub struct CowSlice(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for CowSlice { type EItem = [T]; + type Err = PodCastError; - fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { - try_cast_slice(item).map(Cow::Borrowed).map_err(Into::into) + fn bytes_encode(item: &'a Self::EItem) -> Result, Self::Err> { + try_cast_slice(item).map(Cow::Borrowed) } } impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for CowSlice { type DItem = Cow<'a, [T]>; + type Err = PodCastError; - fn bytes_decode(bytes: &'a [u8]) -> Result { + fn bytes_decode(bytes: &'a [u8]) -> Result { match try_cast_slice(bytes) { Ok(items) => Ok(Cow::Borrowed(items)), Err(PodCastError::AlignmentMismatch) => Ok(Cow::Owned(pod_collect_to_vec(bytes))), - Err(error) => Err(error.into()), + Err(error) => Err(error), } } } diff --git a/heed-types/src/cow_type.rs b/heed-types/src/cow_type.rs index 7f4ff151..b44f15a8 100644 --- a/heed-types/src/cow_type.rs +++ b/heed-types/src/cow_type.rs @@ -1,7 +1,8 @@ use std::borrow::Cow; +use std::convert::Infallible; use bytemuck::{bytes_of, bytes_of_mut, try_from_bytes, AnyBitPattern, NoUninit, PodCastError}; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use heed_traits::{BytesDecode, BytesEncode}; /// Describes a type that must be [memory aligned] and /// will be reallocated if it is not. @@ -28,16 +29,18 @@ pub struct CowType(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for CowType { type EItem = T; + type Err = Infallible; - fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + fn bytes_encode(item: &'a Self::EItem) -> Result, Self::Err> { Ok(Cow::Borrowed(bytes_of(item))) } } impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for CowType { type DItem = Cow<'a, T>; + type Err = PodCastError; - fn bytes_decode(bytes: &'a [u8]) -> Result { + fn bytes_decode(bytes: &'a [u8]) -> Result { match try_from_bytes(bytes) { Ok(item) => Ok(Cow::Borrowed(item)), Err(PodCastError::TargetAlignmentGreaterAndInputNotAligned) => { @@ -45,7 +48,7 @@ impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for CowType { bytes_of_mut(&mut item).copy_from_slice(bytes); Ok(Cow::Owned(item)) } - Err(error) => Err(error.into()), + Err(error) => Err(error), } } } diff --git a/heed-types/src/integer.rs b/heed-types/src/integer.rs index 214d39f2..59b45218 100644 --- a/heed-types/src/integer.rs +++ b/heed-types/src/integer.rs @@ -1,25 +1,28 @@ use std::borrow::Cow; +use std::convert::Infallible; use std::marker::PhantomData; use std::mem::size_of; use byteorder::{ByteOrder, ReadBytesExt}; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use heed_traits::{BytesDecode, BytesEncode}; pub struct U8; impl BytesEncode<'_> for U8 { type EItem = u8; + type Err = Infallible; - fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + fn bytes_encode(item: &Self::EItem) -> Result, Self::Err> { Ok(Cow::from([*item].to_vec())) } } impl BytesDecode<'_> for U8 { type DItem = u8; + type Err = std::io::Error; - fn bytes_decode(mut bytes: &'_ [u8]) -> Result { - bytes.read_u8().map_err(Into::into) + fn bytes_decode(mut bytes: &'_ [u8]) -> Result { + bytes.read_u8() } } @@ -27,16 +30,18 @@ pub struct I8; impl BytesEncode<'_> for I8 { type EItem = i8; + type Err = Infallible; - fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + fn bytes_encode(item: &Self::EItem) -> Result, Self::Err> { Ok(Cow::from([*item as u8].to_vec())) } } impl BytesDecode<'_> for I8 { type DItem = i8; + type Err = std::io::Error; - fn bytes_decode(mut bytes: &'_ [u8]) -> Result { + fn bytes_decode(mut bytes: &'_ [u8]) -> Result { bytes.read_i8().map_err(Into::into) } } @@ -47,8 +52,9 @@ macro_rules! define_type { impl BytesEncode<'_> for $name { type EItem = $native; + type Err = Infallible; - fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + fn bytes_encode(item: &Self::EItem) -> Result, Self::Err> { let mut buf = [0; size_of::()]; O::$write_method(&mut buf, *item); Ok(Cow::from(buf.to_vec())) @@ -57,8 +63,9 @@ macro_rules! define_type { impl BytesDecode<'_> for $name { type DItem = $native; + type Err = std::io::Error; - fn bytes_decode(mut bytes: &'_ [u8]) -> Result { + fn bytes_decode(mut bytes: &'_ [u8]) -> Result { bytes.$read_method::().map_err(Into::into) } } diff --git a/heed-types/src/lib.rs b/heed-types/src/lib.rs index 68596753..499188cb 100644 --- a/heed-types/src/lib.rs +++ b/heed-types/src/lib.rs @@ -37,7 +37,7 @@ mod serde_bincode; #[cfg(feature = "serde-json")] mod serde_json; -use heed_traits::BoxedError; +use std::convert::Infallible; pub use self::cow_slice::CowSlice; pub use self::cow_type::CowType; @@ -63,8 +63,9 @@ pub struct DecodeIgnore; impl heed_traits::BytesDecode<'_> for DecodeIgnore { type DItem = (); + type Err = Infallible; - fn bytes_decode(_bytes: &[u8]) -> Result { + fn bytes_decode(_bytes: &[u8]) -> Result { Ok(()) } } diff --git a/heed-types/src/owned_slice.rs b/heed-types/src/owned_slice.rs index 6b442793..c6ab333a 100644 --- a/heed-types/src/owned_slice.rs +++ b/heed-types/src/owned_slice.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; -use bytemuck::{try_cast_slice, AnyBitPattern, NoUninit}; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use bytemuck::{try_cast_slice, AnyBitPattern, NoUninit, PodCastError}; +use heed_traits::{BytesDecode, BytesEncode}; use crate::CowSlice; @@ -22,16 +22,18 @@ pub struct OwnedSlice(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for OwnedSlice { type EItem = [T]; + type Err = PodCastError; - fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { - try_cast_slice(item).map(Cow::Borrowed).map_err(Into::into) + fn bytes_encode(item: &'a Self::EItem) -> Result, Self::Err> { + try_cast_slice(item).map(Cow::Borrowed) } } impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for OwnedSlice { type DItem = Vec; + type Err = PodCastError; - fn bytes_decode(bytes: &[u8]) -> Result { + fn bytes_decode(bytes: &[u8]) -> Result { CowSlice::::bytes_decode(bytes).map(Cow::into_owned) } } diff --git a/heed-types/src/owned_type.rs b/heed-types/src/owned_type.rs index aa890bae..d95d1829 100644 --- a/heed-types/src/owned_type.rs +++ b/heed-types/src/owned_type.rs @@ -1,7 +1,8 @@ use std::borrow::Cow; +use std::convert::Infallible; -use bytemuck::{bytes_of, AnyBitPattern, NoUninit}; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use bytemuck::{bytes_of, AnyBitPattern, NoUninit, PodCastError}; +use heed_traits::{BytesDecode, BytesEncode}; use crate::CowType; @@ -28,16 +29,18 @@ pub struct OwnedType(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for OwnedType { type EItem = T; + type Err = Infallible; - fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + fn bytes_encode(item: &'a Self::EItem) -> Result, Self::Err> { Ok(Cow::Borrowed(bytes_of(item))) } } impl<'a, T: AnyBitPattern + NoUninit> BytesDecode<'a> for OwnedType { type DItem = T; + type Err = PodCastError; - fn bytes_decode(bytes: &[u8]) -> Result { + fn bytes_decode(bytes: &[u8]) -> Result { CowType::::bytes_decode(bytes).map(Cow::into_owned) } } diff --git a/heed-types/src/serde_bincode.rs b/heed-types/src/serde_bincode.rs index 37fefe01..7c41a3d0 100644 --- a/heed-types/src/serde_bincode.rs +++ b/heed-types/src/serde_bincode.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use heed_traits::{BytesDecode, BytesEncode}; use serde::{Deserialize, Serialize}; /// Describes a type that is [`Serialize`]/[`Deserialize`] and uses `bincode` to do so. @@ -13,9 +13,10 @@ where T: Serialize, { type EItem = T; + type Err = bincode::Error; - fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { - bincode::serialize(item).map(Cow::Owned).map_err(Into::into) + fn bytes_encode(item: &'a Self::EItem) -> Result, Self::Err> { + bincode::serialize(item).map(Cow::Owned) } } @@ -24,9 +25,10 @@ where T: Deserialize<'a>, { type DItem = T; + type Err = bincode::Error; - fn bytes_decode(bytes: &'a [u8]) -> Result { - bincode::deserialize(bytes).map_err(Into::into) + fn bytes_decode(bytes: &'a [u8]) -> Result { + bincode::deserialize(bytes) } } diff --git a/heed-types/src/serde_json.rs b/heed-types/src/serde_json.rs index f1f1c3be..b6ecf293 100644 --- a/heed-types/src/serde_json.rs +++ b/heed-types/src/serde_json.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use heed_traits::{BytesDecode, BytesEncode}; use serde::{Deserialize, Serialize}; /// Describes a type that is [`Serialize`]/[`Deserialize`] and uses `serde_json` to do so. @@ -13,8 +13,9 @@ where T: Serialize, { type EItem = T; + type Err = serde_json::Error; - fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + fn bytes_encode(item: &Self::EItem) -> Result, Self::Err> { serde_json::to_vec(item).map(Cow::Owned).map_err(Into::into) } } @@ -24,9 +25,10 @@ where T: Deserialize<'a>, { type DItem = T; + type Err = serde_json::Error; - fn bytes_decode(bytes: &'a [u8]) -> Result { - serde_json::from_slice(bytes).map_err(Into::into) + fn bytes_decode(bytes: &'a [u8]) -> Result { + serde_json::from_slice(bytes) } } diff --git a/heed-types/src/str.rs b/heed-types/src/str.rs index 4d00ef2e..ba9d87df 100644 --- a/heed-types/src/str.rs +++ b/heed-types/src/str.rs @@ -1,22 +1,26 @@ use std::borrow::Cow; +use std::convert::Infallible; +use std::str::Utf8Error; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use heed_traits::{BytesDecode, BytesEncode}; /// Describes an [`prim@str`]. pub struct Str; impl BytesEncode<'_> for Str { type EItem = str; + type Err = Infallible; - fn bytes_encode(item: &Self::EItem) -> Result, BoxedError> { + fn bytes_encode(item: &Self::EItem) -> Result, Self::Err> { Ok(Cow::Borrowed(item.as_bytes())) } } impl<'a> BytesDecode<'a> for Str { type DItem = &'a str; + type Err = Utf8Error; - fn bytes_decode(bytes: &'a [u8]) -> Result { - std::str::from_utf8(bytes).map_err(Into::into) + fn bytes_decode(bytes: &'a [u8]) -> Result { + std::str::from_utf8(bytes) } } diff --git a/heed-types/src/unaligned_slice.rs b/heed-types/src/unaligned_slice.rs index 7d13a1df..53844b82 100644 --- a/heed-types/src/unaligned_slice.rs +++ b/heed-types/src/unaligned_slice.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; -use bytemuck::{try_cast_slice, AnyBitPattern, NoUninit}; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use bytemuck::{try_cast_slice, AnyBitPattern, NoUninit, PodCastError}; +use heed_traits::{BytesDecode, BytesEncode}; /// Describes a type that is totally borrowed and doesn't /// depends on any [memory alignment]. @@ -15,17 +15,19 @@ pub struct UnalignedSlice(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for UnalignedSlice { type EItem = [T]; + type Err = PodCastError; - fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { - try_cast_slice(item).map(Cow::Borrowed).map_err(Into::into) + fn bytes_encode(item: &'a Self::EItem) -> Result, Self::Err> { + try_cast_slice(item).map(Cow::Borrowed) } } impl<'a, T: AnyBitPattern> BytesDecode<'a> for UnalignedSlice { type DItem = &'a [T]; + type Err = PodCastError; - fn bytes_decode(bytes: &'a [u8]) -> Result { - try_cast_slice(bytes).map_err(Into::into) + fn bytes_decode(bytes: &'a [u8]) -> Result { + try_cast_slice(bytes) } } diff --git a/heed-types/src/unaligned_type.rs b/heed-types/src/unaligned_type.rs index 886aeceb..c45850b8 100644 --- a/heed-types/src/unaligned_type.rs +++ b/heed-types/src/unaligned_type.rs @@ -1,7 +1,8 @@ use std::borrow::Cow; +use std::convert::Infallible; -use bytemuck::{bytes_of, try_from_bytes, AnyBitPattern, NoUninit}; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use bytemuck::{bytes_of, try_from_bytes, AnyBitPattern, NoUninit, PodCastError}; +use heed_traits::{BytesDecode, BytesEncode}; /// Describes a slice that is totally borrowed and doesn't /// depends on any [memory alignment]. @@ -21,17 +22,19 @@ pub struct UnalignedType(std::marker::PhantomData); impl<'a, T: NoUninit> BytesEncode<'a> for UnalignedType { type EItem = T; + type Err = Infallible; - fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError> { + fn bytes_encode(item: &'a Self::EItem) -> Result, Self::Err> { Ok(Cow::Borrowed(bytes_of(item))) } } impl<'a, T: AnyBitPattern> BytesDecode<'a> for UnalignedType { type DItem = &'a T; + type Err = PodCastError; - fn bytes_decode(bytes: &'a [u8]) -> Result { - try_from_bytes(bytes).map_err(Into::into) + fn bytes_decode(bytes: &'a [u8]) -> Result { + try_from_bytes(bytes) } } diff --git a/heed-types/src/unit.rs b/heed-types/src/unit.rs index fee8bd56..7027b950 100644 --- a/heed-types/src/unit.rs +++ b/heed-types/src/unit.rs @@ -1,27 +1,30 @@ use std::borrow::Cow; +use std::convert::Infallible; use bytemuck::PodCastError; -use heed_traits::{BoxedError, BytesDecode, BytesEncode}; +use heed_traits::{BytesDecode, BytesEncode}; /// Describes the `()` type. pub struct Unit; impl BytesEncode<'_> for Unit { type EItem = (); + type Err = Infallible; - fn bytes_encode(_item: &Self::EItem) -> Result, BoxedError> { + fn bytes_encode(_item: &Self::EItem) -> Result, Self::Err> { Ok(Cow::Borrowed(&[])) } } impl BytesDecode<'_> for Unit { type DItem = (); + type Err = PodCastError; - fn bytes_decode(bytes: &[u8]) -> Result { + fn bytes_decode(bytes: &[u8]) -> Result { if bytes.is_empty() { Ok(()) } else { - Err(PodCastError::SizeMismatch.into()) + Err(PodCastError::SizeMismatch) } } } diff --git a/heed/src/db/polymorph.rs b/heed/src/db/polymorph.rs index cc918bc8..d0cb33fc 100644 --- a/heed/src/db/polymorph.rs +++ b/heed/src/db/polymorph.rs @@ -153,14 +153,14 @@ impl PolyDatabase { &self, txn: &'txn RoTxn, key: &'a KC::EItem, - ) -> Result> + ) -> Result, KC::Err, Infallible, Infallible, DC::Err> where KC: BytesEncode<'a>, DC: BytesDecode<'txn>, { assert_eq_env_db_txn!(self, txn); - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::KeyEncoding)?; let mut key_val = unsafe { crate::into_val(&key_bytes) }; let mut data_val = mem::MaybeUninit::uninit(); @@ -172,7 +172,7 @@ impl PolyDatabase { match result { Ok(()) => { let data = unsafe { crate::from_val(data_val.assume_init()) }; - let data = DC::bytes_decode(data).map_err(Error::Decoding)?; + let data = DC::bytes_decode(data).map_err(Error::DataDecoding)?; Ok(Some(data)) } Err(e) if e.not_found() => Ok(None), @@ -227,7 +227,13 @@ impl PolyDatabase { &self, txn: &'txn RoTxn, key: &'a KC::EItem, - ) -> Result> + ) -> Result< + Option<(KC::DItem, DC::DItem)>, + >::Err, + >::Err, + Infallible, + DC::Err, + > where KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>, @@ -235,13 +241,14 @@ impl PolyDatabase { assert_eq_env_db_txn!(self, txn); let mut cursor = RoCursor::new(txn, self.dbi)?; - let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::Encoding)?; + let key_bytes: Cow<[u8]> = KC::bytes_encode(&key).map_err(Error::KeyEncoding)?; cursor.move_on_key_greater_than_or_equal_to(&key_bytes)?; match cursor.move_on_prev() { Ok(Some((key, data))) => match (KC::bytes_decode(key), DC::bytes_decode(data)) { (Ok(key), Ok(data)) => Ok(Some((key, data))), - (Err(e), _) | (_, Err(e)) => Err(Error::Decoding(e)), + (Err(e), _) => Err(Error::KeyDecoding(e)), + (_, Err(e)) => Err(Error::DataDecoding(e)), }, Ok(None) => Ok(None), Err(e) => Err(e), diff --git a/heed/src/lazy_decode.rs b/heed/src/lazy_decode.rs index 3ec3b64e..a1289763 100644 --- a/heed/src/lazy_decode.rs +++ b/heed/src/lazy_decode.rs @@ -1,7 +1,6 @@ +use std::convert::Infallible; use std::marker; -use heed_traits::BoxedError; - /// Lazily decode the data bytes, it can be used to avoid CPU intensive decoding /// before making sure we really need to decode it (e.g. based on the key). #[derive(Default)] @@ -9,8 +8,9 @@ pub struct LazyDecode(marker::PhantomData); impl<'a, C: 'static> heed_traits::BytesDecode<'a> for LazyDecode { type DItem = Lazy<'a, C>; + type Err = Infallible; - fn bytes_decode(bytes: &'a [u8]) -> Result { + fn bytes_decode(bytes: &'a [u8]) -> Result { Ok(Lazy { data: bytes, _phantom: marker::PhantomData }) } } @@ -23,7 +23,7 @@ pub struct Lazy<'a, C> { } impl<'a, C: heed_traits::BytesDecode<'a>> Lazy<'a, C> { - pub fn decode(&self) -> Result { + pub fn decode(&self) -> Result { C::bytes_decode(self.data) } } diff --git a/heed/src/lib.rs b/heed/src/lib.rs index 2609b641..a9196852 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -56,6 +56,7 @@ mod mdb; mod reserved_space; mod txn; +use std::convert::Infallible; use std::{error, fmt, io, result}; use heed_traits as traits; @@ -73,16 +74,18 @@ pub use self::mdb::error::Error as MdbError; use self::mdb::ffi::{from_val, into_val}; pub use self::mdb::flags::Flags; pub use self::reserved_space::ReservedSpace; -pub use self::traits::{BoxedError, BytesDecode, BytesEncode}; +pub use self::traits::{BytesDecode, BytesEncode}; pub use self::txn::{RoTxn, RwTxn}; /// An error that encapsulates all possible errors in this crate. #[derive(Debug)] -pub enum Error { +pub enum Error { Io(io::Error), Mdb(MdbError), - Encoding(BoxedError), - Decoding(BoxedError), + KeyEncoding(KE), + KeyDecoding(KD), + DataEncoding(DE), + DataDecoding(DD), InvalidDatabaseTyping, DatabaseClosing, BadOpenOptions { @@ -93,13 +96,17 @@ pub enum Error { }, } -impl fmt::Display for Error { +impl fmt::Display + for Error +{ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::Io(error) => write!(f, "{}", error), Error::Mdb(error) => write!(f, "{}", error), - Error::Encoding(error) => write!(f, "error while encoding: {}", error), - Error::Decoding(error) => write!(f, "error while decoding: {}", error), + Error::KeyEncoding(error) => write!(f, "error while encoding a key: {}", error), + Error::KeyDecoding(error) => write!(f, "error while decoding a key: {}", error), + Error::DataEncoding(error) => write!(f, "error while encoding a data: {}", error), + Error::DataDecoding(error) => write!(f, "error while decoding a data: {}", error), Error::InvalidDatabaseTyping => { f.write_str("database was previously opened with different types") } @@ -113,10 +120,13 @@ impl fmt::Display for Error { } } -impl error::Error for Error {} +impl error::Error + for Error +{ +} -impl From for Error { - fn from(error: MdbError) -> Error { +impl From for Error { + fn from(error: MdbError) -> Error { match error { MdbError::Other(e) => Error::Io(io::Error::from_raw_os_error(e)), _ => Error::Mdb(error), @@ -124,27 +134,15 @@ impl From for Error { } } -impl From for Error { - fn from(error: io::Error) -> Error { +impl From for Error { + fn from(error: io::Error) -> Error { Error::Io(error) } } /// Either a success or an [`Error`]. -pub type Result = result::Result; - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn error_is_send_sync() { - fn give_me_send_sync(_: T) {} - - let error = Error::Encoding(Box::from("There is an issue, you know?")); - give_me_send_sync(error); - } -} +pub type Result = + result::Result>; macro_rules! assert_eq_env_db_txn { ($database:ident, $txn:ident) => {