1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::borrow::Cow;
use std::error::Error;
use heed_traits::{BytesDecode, BytesEncode};
use bytemuck::PodCastError;
pub struct Unit;
impl BytesEncode<'_> for Unit {
type EItem = ();
fn bytes_encode(_item: &Self::EItem) -> Result<Cow<[u8]>, Box<dyn Error>> {
Ok(Cow::Borrowed(&[]))
}
}
impl BytesDecode<'_> for Unit {
type DItem = ();
fn bytes_decode(bytes: &[u8]) -> Result<Self::DItem, Box<dyn Error>> {
if bytes.is_empty() {
Ok(())
} else {
Err(PodCastError::SizeMismatch.into())
}
}
}