pub trait 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§
Sourcetype SendContext: ContextType
type SendContext: ContextType
Context provided to ContentType::send inside TcpMessage::send, created in MetaDataType::send.
Sourcetype ReceiveContext: ContextType
type ReceiveContext: ContextType
Context provided to ContentType::receive inside TcpMessage::receive, created in MetaDataType::send.
Sourcetype SendOutput: OutputType
type SendOutput: OutputType
Output of ContentType::send that is used as an output of
TcpMessage::send.
Sourcetype ReceiveOutput: OutputType
type ReceiveOutput: OutputType
Output of ContentType::receive that is used as an output of
TcpMessage::receive.
Required Methods§
Sourcefn send(
self,
stream: &mut TcpStream,
context: Option<Self::SendContext>,
) -> Result<Option<Self::SendOutput>, Error>
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
stream– TcpStream on which are data being sent.context– Optional context provided TcpMessage::send which is ContentType::SendContext and created inside MetaDataType::send.
Sourcefn receive(
stream: &mut TcpStream,
metadata: &M,
context: Option<Self::ReceiveContext>,
) -> Result<(Self, Packet, Option<<C as ContentType<'a, M, C>>::ReceiveOutput>), Error>
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.
Self– Receivedcontentofmessage.Packet– Receivedend dataof amessageas thispacketmarks end of amessageit need to be returned from this method. But depending on implementation, thispacketdoes not need to be valid.- Option of ContentType::ReceiveOutput on C ContentType::ReceiveOutput
to provide an
outputfrom both this method and TcpMessage::receive.
§Arguments
stream– TcpStream on which are data being received.metadata– a reference for already receivedmetadata.context– Optional context provided inside TcpMessage::receive which is ContentType::ReceiveContext, created inside MetaDataType::receive.
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.