milli_core/heed_codec/
byte_slice_ref.rs

1use std::borrow::Cow;
2
3use heed::{BoxedError, BytesDecode, BytesEncode};
4
5/// A codec for values of type `&[u8]`. Unlike `Bytes`, its `EItem` and `DItem` associated
6/// types are equivalent (= `&'a [u8]`) and these values can reside within another structure.
7pub struct BytesRefCodec;
8
9impl<'a> BytesEncode<'a> for BytesRefCodec {
10    type EItem = &'a [u8];
11
12    fn bytes_encode(item: &'a Self::EItem) -> Result<Cow<'a, [u8]>, BoxedError> {
13        Ok(Cow::Borrowed(item))
14    }
15}
16
17impl<'a> BytesDecode<'a> for BytesRefCodec {
18    type DItem = &'a [u8];
19
20    fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> {
21        Ok(bytes)
22    }
23}