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