meilisearch / heed

A fully typed LMDB wrapper with minimum overhead 🐦
https://docs.rs/heed
MIT License
609 stars 55 forks source link

Type the error in the traits `BytesEncode` and `BytesDecode` #165

Open irevoire opened 1 year ago

irevoire commented 1 year ago

It's strange not to be able to return a typed error with the BytesEncode and BytesDecode traits.

It would be nice to have something like that;

/// 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<Cow<'a, [u8]>, 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<Self::DItem, Self::Err>;
}