TcpMessage

Trait TcpMessage 

Source
pub trait TcpMessage<'a, M, C>
where Self: Default, M: MetaDataType<'a, M, C>, C: ContentType<'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§

Source

fn destructure(self) -> (M, C, Packet)

Breaks self into metadata, content and end_data.

Source

fn build(metadata: M, content: C, end_data: Packet) -> Self

Builds Self from metadata, content and end_data.

Provided Methods§

Source

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

This uses send methods implemented by metadata and content.

Source

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

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.

Implementors§