Trait nardol::TcpMessage
source · [−]pub trait TcpMessage<'a, M, C> where
Self: Default,
M: MetaDataType<'a, M, C>,
C: ContentType<'a, M, C>, {
fn destructure(self) -> (M, C, Packet);
fn build(metadata: M, content: C, end_data: Packet) -> Self;
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
fn destructure(self) -> (M, C, Packet)
fn destructure(self) -> (M, C, Packet)
Breaks self
into metadata
, content
and end_data
.
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 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
– Optionalcontext
to provide additional data if necessary which has same type as MetaDataType::SendContext on associated M.
This uses send
methods implemented by metadata
and content
.
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>
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
– Optionalcontext
to provide additional data if necessary which has same type as MetaDataType::ReceiveContext on associated M.