use std::borrow::Cow; use heed::{types::CowSlice, BytesEncode, BytesDecode}; use sdset::{Set, SetBuf}; use zerocopy::{AsBytes, FromBytes}; pub struct CowSet(std::marker::PhantomData); impl<'a, T: 'a> BytesEncode<'a> for CowSet where T: AsBytes, { type EItem = Set; fn bytes_encode(item: &'a Self::EItem) -> Option> { CowSlice::bytes_encode(item.as_slice()) } } impl<'a, T: 'a> BytesDecode<'a> for CowSet where T: FromBytes + Copy, { type DItem = Cow<'a, Set>; fn bytes_decode(bytes: &'a [u8]) -> Option { match CowSlice::::bytes_decode(bytes)? { Cow::Owned(vec) => Some(Cow::Owned(SetBuf::new_unchecked(vec))), Cow::Borrowed(slice) => Some(Cow::Borrowed(Set::new_unchecked(slice))), } } }