feat: default postcard 1.0

This commit is contained in:
Vincent Herlemont
2023-10-29 09:43:15 +01:00
parent 39466299ed
commit f07922cdb4
7 changed files with 44 additions and 5 deletions
+1
View File
@@ -1,5 +1,6 @@
pub mod bincode_1_3;
pub mod bincode_2_rc;
pub mod postcard_1_0;
/// Encode trait for your own encoding method.
///
@@ -0,0 +1,18 @@
use postcard_1_0::{from_bytes, to_allocvec, Error};
use serde::{Deserialize, Serialize};
pub struct PostCard;
impl<T: Serialize> super::Encode<T> for PostCard {
type Error = Error;
fn encode(obj: &T) -> Result<Vec<u8>, Error> {
Ok(to_allocvec(obj)?)
}
}
impl<T: for<'a> Deserialize<'a>> super::Decode<T> for PostCard {
type Error = Error;
fn decode(data: Vec<u8>) -> Result<T, Error> {
Ok(from_bytes(&data)?)
}
}