2023-05-02 09:34:28 +02:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2023-04-26 17:09:59 +02:00
|
|
|
use fst::Set;
|
2023-11-22 18:21:19 +01:00
|
|
|
use heed::{BoxedError, BytesDecode, BytesEncode};
|
2023-05-02 09:34:28 +02:00
|
|
|
|
|
|
|
/// A codec for values of type `Set<&[u8]>`.
|
|
|
|
pub struct FstSetCodec;
|
|
|
|
|
|
|
|
impl<'a> BytesEncode<'a> for FstSetCodec {
|
|
|
|
type EItem = Set<Vec<u8>>;
|
|
|
|
|
2023-11-22 18:21:19 +01:00
|
|
|
fn bytes_encode(item: &'a Self::EItem) -> Result<Cow<'a, [u8]>, BoxedError> {
|
|
|
|
Ok(Cow::Borrowed(item.as_fst().as_bytes()))
|
2023-05-02 09:34:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> BytesDecode<'a> for FstSetCodec {
|
|
|
|
type DItem = Set<&'a [u8]>;
|
|
|
|
|
2023-11-22 18:21:19 +01:00
|
|
|
fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, BoxedError> {
|
|
|
|
Set::new(bytes).map_err(Into::into)
|
2023-05-02 09:34:28 +02:00
|
|
|
}
|
|
|
|
}
|