2023-05-02 15:34:28 +08:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2023-04-26 23:09:59 +08:00
|
|
|
use fst::Set;
|
2023-05-02 15:34:28 +08: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> {
|
2023-04-27 00:35:06 +08:00
|
|
|
Set::new(bytes).ok()
|
2023-05-02 15:34:28 +08:00
|
|
|
}
|
|
|
|
}
|