thingvellir 0.0.2-alpha1

a concurrent, shared-nothing abstraction that manages an assembly of things
Documentation
#[cfg(feature = "cbor")]
use serde::{Deserialize, Serialize};

pub trait WireSerializer<V>: Clone + Send + 'static {
    type Error: std::error::Error + Send + 'static;

    fn serialize(&self, value: &V) -> Result<Vec<u8>, Self::Error>;
    fn deserialize(&self, buf: &[u8]) -> Result<V, Self::Error>;
}

#[cfg(feature = "cbor")]
#[derive(Clone)]
pub struct CborSerializer;

#[cfg(feature = "cbor")]
impl<V> WireSerializer<V> for CborSerializer
where
    V: Serialize,
    V: for<'de> Deserialize<'de>,
{
    type Error = serde_cbor::error::Error;

    fn serialize(&self, value: &V) -> Result<Vec<u8>, Self::Error> {
        serde_cbor::to_vec(value)
    }
    fn deserialize(&self, buf: &[u8]) -> Result<V, Self::Error> {
        serde_cbor::from_reader(buf)
    }
}