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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::borrow::Cow;
use std::error::Error;
use bytemuck::Pod;
use heed_traits::{BytesDecode, BytesEncode};
use crate::CowSlice;
pub struct OwnedSlice<T>(std::marker::PhantomData<T>);
impl<'a, T: Pod> BytesEncode<'a> for OwnedSlice<T> {
type EItem = [T];
fn bytes_encode(item: &'a Self::EItem) -> Result<Cow<'a, [u8]>, Box<dyn Error>> {
CowSlice::bytes_encode(item)
}
}
impl<'a, T: Pod> BytesDecode<'a> for OwnedSlice<T> {
type DItem = Vec<T>;
fn bytes_decode(bytes: &[u8]) -> Result<Self::DItem, Box<dyn Error>> {
CowSlice::bytes_decode(bytes).map(Cow::into_owned)
}
}
unsafe impl<T> Send for OwnedSlice<T> {}
unsafe impl<T> Sync for OwnedSlice<T> {}