use super::Bytes;
use anyhow::{Context, Result};
use bincode::{deserialize, serialize};
pub use serde::{Deserialize, Serialize};
pub trait Sendable {
fn to_bytes(&self) -> Result<Bytes>;
fn from_bytes(bytes: &Bytes) -> Result<Self>
where
Self: Sized;
}
impl<T> Sendable for T
where
T: Serialize + for<'de> Deserialize<'de> + Send + 'static,
{
fn to_bytes(&self) -> Result<Bytes> {
serialize(self).context("Failed to serialize object")
}
fn from_bytes(bytes: &Bytes) -> Result<Self> {
deserialize(bytes).context("Failed to deserialize object")
}
}