mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-24 08:53:04 +10:00
feat: default postcard 1.0
This commit is contained in:
@@ -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)?)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user