pub struct Message<'a>(/* private fields */);
Expand description
A message on a port.
The message may reference data with non-static lifetime, and it may not be
Send
. See OwnedMessage
for a version that is Send
.
Implementations§
Source§impl<'a> Message<'a>
impl<'a> Message<'a>
Sourcepub fn new<T: SerializeMessage + Send>(message: T) -> Self
pub fn new<T: SerializeMessage + Send>(message: T) -> Self
Returns a new instance wrapping message
. The message will be boxed and
will be lazily serialized when needed.
Sourcepub fn serialized(data: &'a [u8], resources: Vec<Resource>) -> Self
pub fn serialized(data: &'a [u8], resources: Vec<Resource>) -> Self
Returns an instance for a serialized message with data
and
resources
.
Sourcepub fn into_owned(self) -> OwnedMessage
pub fn into_owned(self) -> OwnedMessage
Converts the message into an OwnedMessage
.
If the message was created with Message::new
or
From<OwnedMessage>
, then this operation is cheap. Otherwise, this
operation will serialize the message and allocate a new buffer.
Sourcepub fn serialize(self) -> (Cow<'a, [u8]>, Vec<Resource>)
pub fn serialize(self) -> (Cow<'a, [u8]>, Vec<Resource>)
Serializes the message and returns it.
If the message is already serialized, then this is a cheap operation.
Sourcepub fn parse<T>(self) -> Result<T, Error>
pub fn parse<T>(self) -> Result<T, Error>
Parses the message into a value of type T
.
If the message was constructed with new<T>
, then the round trip
serialization/deserialization is skipped.
Sourcepub fn parse_non_static<T>(self) -> Result<T, Error>
pub fn parse_non_static<T>(self) -> Result<T, Error>
Parses the message into a value of type T
.
When T
has static lifetime, prefer Message::parse
instead, since
it can recover a T
passed to Message::new
without round-trip
serialization.
Trait Implementations§
Source§impl DefaultEncoding for Message<'_>
impl DefaultEncoding for Message<'_>
Source§type Encoding = MessageEncoding<MessageEncoder>
type Encoding = MessageEncoding<MessageEncoder>
Source§impl From<OwnedMessage> for Message<'_>
impl From<OwnedMessage> for Message<'_>
Source§fn from(m: OwnedMessage) -> Self
fn from(m: OwnedMessage) -> Self
Source§impl MessageEncode<Message<'_>, Resource> for MessageEncoder
impl MessageEncode<Message<'_>, Resource> for MessageEncoder
Source§fn write_message(item: Message<'_>, writer: MessageWriter<'_, '_, Resource>)
fn write_message(item: Message<'_>, writer: MessageWriter<'_, '_, Resource>)
item
as a message.Source§fn compute_message_size(item: &mut Message<'_>, sizer: MessageSizer<'_>)
fn compute_message_size(item: &mut Message<'_>, sizer: MessageSizer<'_>)
item
as a message. Read more