Trait ContentType

Source
pub trait ContentType<'a, M, C>
where Self: Sized, M: MetaDataType<'a, M, C>, C: ContentType<'a, M, C>,
{ type SendContext: ContextType; type ReceiveContext: ContextType; type SendOutput: OutputType; type ReceiveOutput: OutputType; // Required methods fn send( self, stream: &mut TcpStream, context: Option<Self::SendContext>, ) -> Result<Option<Self::SendOutput>, Error>; fn receive( stream: &mut TcpStream, metadata: &M, context: Option<Self::ReceiveContext>, ) -> Result<(Self, Packet, Option<<C as ContentType<'a, M, C>>::ReceiveOutput>), Error>; }
Expand description

Trait that needs to be implemented for type that will be used as content inside a message.

Required Associated Types§

Source

type SendContext: ContextType

Context provided to ContentType::send inside TcpMessage::send, created in MetaDataType::send.

Source

type ReceiveContext: ContextType

Context provided to ContentType::receive inside TcpMessage::receive, created in MetaDataType::send.

Source

type SendOutput: OutputType

Output of ContentType::send that is used as an output of TcpMessage::send.

Source

type ReceiveOutput: OutputType

Output of ContentType::receive that is used as an output of TcpMessage::receive.

Required Methods§

Source

fn send( self, stream: &mut TcpStream, context: Option<Self::SendContext>, ) -> Result<Option<Self::SendOutput>, Error>

Send method used to send content inside TcpMessage::send.

Defines how content is send.

Returns an optional ContentType::SendOutput if successful or an Error if not.

§Arguments
Source

fn receive( stream: &mut TcpStream, metadata: &M, context: Option<Self::ReceiveContext>, ) -> Result<(Self, Packet, Option<<C as ContentType<'a, M, C>>::ReceiveOutput>), Error>

Receive method used to receive content inside TcpMessage::receive.

Defines how content are received.

Returns a tuple 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§