Trait Codec
pub trait Codec {
type Protocol: AsRef<str> + Send + Clone;
type Request: Send;
type Response: Send;
// Required methods
fn read_request<T>(
&mut self,
protocol: &Self::Protocol,
io: &mut T,
) -> impl Future<Output = Result<Self::Request, Error>> + Send
where T: AsyncRead + Unpin + Send;
fn read_response<T>(
&mut self,
protocol: &Self::Protocol,
io: &mut T,
) -> impl Future<Output = Result<Self::Response, Error>> + Send
where T: AsyncRead + Unpin + Send;
fn write_request<T>(
&mut self,
protocol: &Self::Protocol,
io: &mut T,
req: Self::Request,
) -> impl Future<Output = Result<(), Error>> + Send
where T: AsyncWrite + Unpin + Send;
fn write_response<T>(
&mut self,
protocol: &Self::Protocol,
io: &mut T,
res: Self::Response,
) -> impl Future<Output = Result<(), Error>> + Send
where T: AsyncWrite + Unpin + Send;
}Available on crate feature
request-response only.Expand description
A Codec defines the request and response types
for a request-response Behaviour protocol or
protocol family and how they are encoded / decoded on an I/O stream.
Required Associated Types§
Required Methods§
fn read_request<T>(
&mut self,
protocol: &Self::Protocol,
io: &mut T,
) -> impl Future<Output = Result<Self::Request, Error>> + Send
fn read_request<T>( &mut self, protocol: &Self::Protocol, io: &mut T, ) -> impl Future<Output = Result<Self::Request, Error>> + Send
Reads a request from the given I/O stream according to the negotiated protocol.
fn read_response<T>(
&mut self,
protocol: &Self::Protocol,
io: &mut T,
) -> impl Future<Output = Result<Self::Response, Error>> + Send
fn read_response<T>( &mut self, protocol: &Self::Protocol, io: &mut T, ) -> impl Future<Output = Result<Self::Response, Error>> + Send
Reads a response from the given I/O stream according to the negotiated protocol.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".