mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-23 20:38:21 -06:00
undo
This commit is contained in:
parent
c8ff99e98c
commit
48e56f5275
|
@ -2,7 +2,6 @@ pub mod client;
|
|||
pub mod server;
|
||||
pub(crate) mod packet;
|
||||
pub(crate) mod common;
|
||||
pub(crate) mod serializable;
|
||||
pub use common::ClientId;
|
||||
|
||||
//pub(crate) trait Serializable: bincode::Encode + bincode::Decode {}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
use anyhow::Result;
|
||||
use crate::BINCODE_CONFIG;
|
||||
|
||||
pub trait Serializable: bincode::Encode + bincode::Decode {
|
||||
fn serialize(&self, buf: &mut [u8]) -> Result<()>;
|
||||
fn deserialize(buf: &[u8]) -> Result<Self>;
|
||||
|
||||
fn serialize_to_vec(&self) -> Result<Vec<u8>> {
|
||||
let mut buf = Vec::new();
|
||||
self.serialize(&mut buf)?;
|
||||
Ok(buf)
|
||||
}
|
||||
}
|
||||
impl<T: bincode::Encode + bincode::Decode> Serializable for T {
|
||||
fn serialize(&self, buf: &mut [u8]) -> Result<()> {
|
||||
bincode::encode_into_slice(self, buf, BINCODE_CONFIG)?;
|
||||
Ok(())
|
||||
}
|
||||
fn deserialize(buf: &[u8]) -> Result<Self> {
|
||||
bincode::decode_from_slice(buf, BINCODE_CONFIG)?.0
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue