[][src]Struct nng::Message

pub struct Message { /* fields omitted */ }

An nng message type.

Applications desiring to use the richest part of nng will want to use the message API, where the message structure is passed between functions. This API provides the most powerful support for zero-copy.

In addition to the regular portion of the message there is a header that carries protocol specific header information. Most applications will not need to touch the header and will only interact with the regular message.

Methods

impl Message[src]

pub fn new() -> Result<Self>[src]

Create an empty message.

pub fn with_capacity(cap: usize) -> Result<Self>[src]

Create an empty message with a pre-allocated body buffer.

The returned buffer will have a capacity equal to cap but a length of zero. To get a Message with a specified length, use Message::zeros.

pub fn with_zeros(size: usize) -> Result<Self>[src]

Create a message that is filled to size with zeros.

pub fn from_slice(s: &[u8]) -> Result<Self>[src]

Attempts to convert a buffer into a message.

This is functionally equivalent to calling From but allows the user to handle the case of nng being out of memory.

pub fn truncate(&mut self, len: usize)[src]

Shortens the message, dropping excess elements from the back.

If len is greater than the message body's current length, this has no effect.

pub fn trim(&mut self, len: usize)[src]

Remove the first len bytes from the front of the message body.

If len is greater than the message body's current length then this will clear the entire message.

pub fn as_slice(&self) -> &[u8][src]

Returns a slice that contains the contents of the message body.

pub fn as_mut_slice(&mut self) -> &mut [u8][src]

Returns a mutable slice that contains the contents of the message body.

Important traits for Header
pub const fn as_header(&self) -> &Header[src]

Returns a reference to the message header.

Important traits for Header
pub fn as_mut_header(&mut self) -> &mut Header[src]

Returns a mutable reference to the message header.

pub fn len(&self) -> usize[src]

Returns the length of the message.

pub fn is_empty(&self) -> bool[src]

Returns true if the message body is empty.

pub fn clear(&mut self)[src]

Clears the message body.

pub fn push_front(&mut self, data: &[u8]) -> Result<()>[src]

Prepends the data to the message body.

pub fn push_back(&mut self, data: &[u8]) -> Result<()>[src]

Appends the data to the back of the message body.

pub fn try_clone(&self) -> Result<Self>[src]

Attempts to duplicate the message.

This is functionally equivalent to calling Clone but allows the user to handle the case of nng being out of memory.

pub fn pipe(&mut self) -> Option<Pipe>[src]

Returns the pipe object associated with the message.

On receive, this is the pipe from which the message was received. On transmit, this would be the pipe that the message should be delivered to, if a specific peer is required. Note that not all protocols support overriding the destination pipe.

The most usual use case for this is to obtain information about the peer from which the message was received. This can be used to provide different behaviors for different peers, such as a higher level of authentication for peers located on an untrusted network.

pub fn set_pipe(&mut self, pipe: Pipe)[src]

Sets the pipe associated with the message.

This is most useful when used with protocols that support directing a message to a specific peer. For example, the pair version 1 protocol can do this when in polyamorous mode. Not all protocols support this.

Trait Implementations

impl Send for Message[src]

impl Sync for Message[src]

impl Drop for Message[src]

impl<'a> From<&'a [u8]> for Message[src]

impl<'a> From<&'a Vec<u8>> for Message[src]

impl Extend<u8> for Message[src]

impl<'a> Extend<&'a u8> for Message[src]

impl Clone for Message[src]

impl Default for Message[src]

impl Deref for Message[src]

type Target = [u8]

The resulting type after dereferencing.

impl DerefMut for Message[src]

impl Debug for Message[src]

impl<I: SliceIndex<[u8]>> Index<I> for Message[src]

type Output = I::Output

The returned type after indexing.

impl<I: SliceIndex<[u8]>> IndexMut<I> for Message[src]

impl FromIterator<u8> for Message[src]

impl<'a> FromIterator<&'a u8> for Message[src]

impl Write for Message[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]