mesh_node::message

Struct Message

Source
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>

Source

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.

Source

pub fn serialized(data: &'a [u8], resources: Vec<Resource>) -> Self

Returns an instance for a serialized message with data and resources.

Source

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.

Source

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.

Source

pub fn parse<T>(self) -> Result<T, Error>
where T: 'static + DefaultEncoding, T::Encoding: for<'b> MessageDecode<'b, T, Resource>,

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.

Source

pub fn parse_non_static<T>(self) -> Result<T, Error>
where T: DefaultEncoding, T::Encoding: for<'b> MessageDecode<'b, T, Resource>,

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 Debug for Message<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DefaultEncoding for Message<'_>

Source§

type Encoding = MessageEncoding<MessageEncoder>

The encoding to use for the serialization. Read more
Source§

impl From<OwnedMessage> for Message<'_>

Source§

fn from(m: OwnedMessage) -> Self

Converts to this type from the input type.
Source§

impl MessageEncode<Message<'_>, Resource> for MessageEncoder

Source§

fn write_message(item: Message<'_>, writer: MessageWriter<'_, '_, Resource>)

Writes item as a message.
Source§

fn compute_message_size(item: &mut Message<'_>, sizer: MessageSizer<'_>)

Computes the size of item as a message. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Message<'a>

§

impl<'a> !RefUnwindSafe for Message<'a>

§

impl<'a> !Send for Message<'a>

§

impl<'a> !Sync for Message<'a>

§

impl<'a> Unpin for Message<'a>

§

impl<'a> !UnwindSafe for Message<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more