pub trait TcpMessage<'a, M, C>{
// Required methods
fn destructure(self) -> (M, C, Packet);
fn build(metadata: M, content: C, end_data: Packet) -> Self;
// Provided methods
fn send(
self,
stream: &mut TcpStream,
context: Option<<M as MetaDataType<'a, M, C>>::SendContext>,
) -> Result<Option<<C as ContentType<'a, M, C>>::SendOutput>, Error> { ... }
fn receive(
stream: &mut TcpStream,
context: Option<<M as MetaDataType<'a, M, C>>::ReceiveContext>,
) -> Result<(Self, Option<<C as ContentType<'a, M, C>>::ReceiveOutput>), Error> { ... }
}Expand description
Trait that allows implementor to send and receive itself via TcpStream with provided TcpMessage::send and TcpMessage::receive.
Required Methods§
Sourcefn destructure(self) -> (M, C, Packet)
fn destructure(self) -> (M, C, Packet)
Breaks self into metadata, content and end_data.
Provided Methods§
Sourcefn send(
self,
stream: &mut TcpStream,
context: Option<<M as MetaDataType<'a, M, C>>::SendContext>,
) -> Result<Option<<C as ContentType<'a, M, C>>::SendOutput>, Error>
fn send( self, stream: &mut TcpStream, context: Option<<M as MetaDataType<'a, M, C>>::SendContext>, ) -> Result<Option<<C as ContentType<'a, M, C>>::SendOutput>, Error>
Sends Self via stream.
Returns an optional output which is ContentType::SendOutput on
associated C if successful or an Error if not.
§Arguments
stream– TcpStream that is used to send a message.context– Optionalcontextto provide additional data if necessary which has same type as MetaDataType::SendContext on associated M.
This uses send methods implemented by metadata and content.
Sourcefn receive(
stream: &mut TcpStream,
context: Option<<M as MetaDataType<'a, M, C>>::ReceiveContext>,
) -> Result<(Self, Option<<C as ContentType<'a, M, C>>::ReceiveOutput>), Error>
fn receive( stream: &mut TcpStream, context: Option<<M as MetaDataType<'a, M, C>>::ReceiveContext>, ) -> Result<(Self, Option<<C as ContentType<'a, M, C>>::ReceiveOutput>), Error>
Receives a message on stream.
Returns a tuple of Self and an optional output which is
ContentType::ReceiveOutput on associated C if successful or an
Error if not.
§Arguments
stream– TcpStream that is used to receive a message on.context– Optionalcontextto provide additional data if necessary which has same type as MetaDataType::ReceiveContext on associated M.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.