diff --git a/heed-traits/src/lib.rs b/heed-traits/src/lib.rs index 340be438..bb7a2cbe 100644 --- a/heed-traits/src/lib.rs +++ b/heed-traits/src/lib.rs @@ -9,28 +9,12 @@ #![warn(missing_docs)] -use std::borrow::Cow; use std::cmp::{Ord, Ordering}; use std::error::Error as StdError; -use std::fmt; /// A boxed `Send + Sync + 'static` error. pub type BoxedError = Box; -/// A trait that represents an encoding structure. -#[deprecated = "replaced by `ToBytes` to allow for more optimization"] -#[allow(deprecated)] // deprecated BoxedErrorWrapper is used in a bound -pub trait BytesEncode<'a>: - // TODO are these bound needed? - ToBytes<'a, SelfType = Self::EItem, ReturnBytes = Cow<'a, [u8]>, Error = BoxedErrorWrapper> -{ - /// The type to encode. - type EItem: ?Sized + 'a; - - /// Encode the given item as bytes. - fn bytes_encode(item: &'a Self::EItem) -> Result, BoxedError>; -} - /// A trait that represents an encoding structure. pub trait ToBytes<'a> { /// The type to encode to bytes. @@ -44,45 +28,15 @@ pub trait ToBytes<'a> { /// Encode the given item as bytes. fn to_bytes(item: &'a Self::SelfType) -> Result; -} - -#[allow(deprecated)] -impl<'a, T: BytesEncode<'a>> ToBytes<'a> for T { - type SelfType = >::EItem; - - type ReturnBytes = Cow<'a, [u8]>; - - type Error = BoxedErrorWrapper; - - fn to_bytes(item: &'a Self::SelfType) -> Result { - Self::bytes_encode(item).map_err(BoxedErrorWrapper) - } -} - -/// Wraps the [`BoxedError`] type alias because for complicated reasons it does not implement -/// [`Error`][StdError]. This wrapper forwards [`Debug`][fmt::Debug], [`Display`][fmt::Display] -/// and [`Error`][StdError] through the wrapper and the [`Box`]. -#[deprecated = "this wrapper was added for backwards compatibility of BytesEncode only"] -pub struct BoxedErrorWrapper(BoxedError); - -#[allow(deprecated)] -impl fmt::Debug for BoxedErrorWrapper { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - ::fmt(&self.0, f) - } -} - -#[allow(deprecated)] -impl fmt::Display for BoxedErrorWrapper { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - ::fmt(&self.0, f) - } -} -#[allow(deprecated)] -impl StdError for BoxedErrorWrapper { - fn source(&self) -> Option<&(dyn StdError + 'static)> { - self.0.source() + /// Encode the given item as bytes and write it into the writer. This function by default + /// forwards to `to_bytes`. + fn bytes_encode_into_writer( + item: &'a Self::SelfType, + writer: &mut Vec, + ) -> Result<(), Self::Error> { + writer.extend_from_slice(Self::to_bytes(item)?.as_ref()); + Ok(()) } } diff --git a/heed-types/src/serde_bincode.rs b/heed-types/src/serde_bincode.rs index 63e85a3a..0b027f1e 100644 --- a/heed-types/src/serde_bincode.rs +++ b/heed-types/src/serde_bincode.rs @@ -16,7 +16,7 @@ where type Error = bincode::Error; - fn to_bytes(item: &'a Self::SelfType) -> Result { + fn to_bytes(item: &Self::SelfType) -> Result { bincode::serialize(item) } } diff --git a/heed-types/src/serde_json.rs b/heed-types/src/serde_json.rs index 13045a4a..95531890 100644 --- a/heed-types/src/serde_json.rs +++ b/heed-types/src/serde_json.rs @@ -16,7 +16,7 @@ where type Error = serde_json::Error; - fn to_bytes(item: &'a Self::SelfType) -> Result { + fn to_bytes(item: &Self::SelfType) -> Result { serde_json::to_vec(item) } } diff --git a/heed-types/src/serde_rmp.rs b/heed-types/src/serde_rmp.rs index 418ead93..15698689 100644 --- a/heed-types/src/serde_rmp.rs +++ b/heed-types/src/serde_rmp.rs @@ -16,7 +16,7 @@ where type Error = rmp_serde::encode::Error; - fn to_bytes(item: &'a Self::SelfType) -> Result { + fn to_bytes(item: &Self::SelfType) -> Result { rmp_serde::to_vec(item) } } diff --git a/heed-types/src/unit.rs b/heed-types/src/unit.rs index 69f13fa0..97bebe3d 100644 --- a/heed-types/src/unit.rs +++ b/heed-types/src/unit.rs @@ -13,7 +13,7 @@ impl ToBytes<'_> for Unit { type Error = Infallible; - fn to_bytes(_item: &'_ Self::SelfType) -> Result { + fn to_bytes(&(): &Self::SelfType) -> Result { Ok([]) } } diff --git a/heed/src/lib.rs b/heed/src/lib.rs index cef0904b..950b6ec1 100644 --- a/heed/src/lib.rs +++ b/heed/src/lib.rs @@ -92,10 +92,7 @@ pub use self::mdb::error::Error as MdbError; use self::mdb::ffi::{from_val, into_val}; pub use self::mdb::flags::{DatabaseFlags, EnvFlags, PutFlags}; pub use self::reserved_space::ReservedSpace; -#[allow(deprecated)] // re-exports BytesEncode -pub use self::traits::{ - BoxedError, BytesDecode, BytesEncode, Comparator, LexicographicComparator, ToBytes, -}; +pub use self::traits::{BoxedError, BytesDecode, Comparator, LexicographicComparator, ToBytes}; pub use self::txn::{RoTxn, RwTxn}; /// The underlying LMDB library version information.