heed_types/
bytes.rs

1use std::borrow::Cow;
2
3use heed_traits::{BoxedError, BytesDecode, BytesEncode};
4
5/// Describes a byte slice `[u8]` that is totally borrowed and doesn't depend on
6/// any [memory alignment].
7///
8/// [memory alignment]: std::mem::align_of()
9pub enum Bytes {}
10
11impl<'a> BytesEncode<'a> for Bytes {
12    type EItem = [u8];
13
14    fn bytes_encode(item: &'a Self::EItem) -> Result<Cow<[u8]>, BoxedError> {
15        Ok(Cow::Borrowed(item))
16    }
17}
18
19impl<'a> BytesDecode<'a> for Bytes {
20    type DItem = &'a [u8];
21
22    fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> {
23        Ok(bytes)
24    }
25}