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
use super::Format;
use serde::{de::DeserializeSeed, Serialize};
use crate::kind::Fallible;
pub struct Bincode;
impl Format for Bincode {
type Representation = Vec<u8>;
type Error = serde_bincode::Error;
fn serialize<T: Serialize>(item: T) -> Self::Representation {
serde_bincode::serialize(&item).unwrap()
}
fn deserialize<'de, T: DeserializeSeed<'de>>(
item: Self::Representation,
context: T,
) -> Fallible<T::Value, (Self::Error, Self::Representation)>
where
T: Sync + Send + 'static,
{
Box::pin(async move {
serde_bincode::config()
.deserialize_from_seed(context, item.as_slice())
.map_err(|e| (e, item))
})
}
}