mod node; use serde::{de::DeserializeOwned, Serialize}; use uuid::Uuid; use crate::{utils::async_convert::{AsyncTryFrom, AsyncTryInto}, error::Error}; pub trait Message: DeserializeOwned + Sized + Serialize { fn into_writer(&self, writer: W) -> Result<(), ciborium::ser::Error> { ciborium::into_writer(self, writer) } fn into_vec_u8(&self) -> Result, ciborium::ser::Error> { let mut buf: Vec = Vec::new(); self.into_writer(&mut buf)?; Ok(buf) } fn from_reader(reader: R) -> Result> { ciborium::from_reader(reader) } } pub trait Request: Into + From + AsyncTryInto where T: Message { type Response: Response; async fn send_p2p(self) -> Result; } pub trait Response: Into + From + AsyncTryFrom where T: Message{ type Request: Request; async fn from_request_with_local(req: Self::Request) -> Result; async fn from_request_with_p2p(req: Self::Request) -> Result { todo!() } } pub trait FromDatabase { async fn from_storage(); } pub trait P2pRequest: Into + From where T: Message { type P2pResponse: P2pResponse; async fn send_p2p(&self) -> Result{ todo!() } } pub trait P2pResponse: Into + From + AsyncTryFrom<(Self::P2pRequest)> where T: Message { type P2pRequest: P2pRequest; async fn try_from_p2p_request(source: Self::P2pRequest) -> Result; }