Trait nardol::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;
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
type SendContext: ContextType
type SendContext: ContextType
Context provided to ContentType::send inside TcpMessage::send, created in MetaDataType::send.
Context provided to ContentType::receive inside TcpMessage::receive, created in MetaDataType::send.
type SendOutput: OutputType
type SendOutput: OutputType
Output of ContentType::send that is used as an output
of
TcpMessage::send.
Output of ContentType::receive that is used as an output
of
TcpMessage::receive.
Required Methods
fn 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.
fn 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
– Receivedcontent
ofmessage
.Packet
– Receivedend data
of amessage
as thispacket
marks end of amessage
it need to be returned from this method. But depending on implementation, thispacket
does not need to be valid.- Option of ContentType::ReceiveOutput on C ContentType::ReceiveOutput
to provide an
output
from 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.