[−][src]Struct nng::Message
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 Headerpub const fn as_header(&self) -> &Header
[src]
Returns a reference to the message header.
ⓘImportant traits for Headerpub 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]
fn extend<I: IntoIterator<Item = u8>>(&mut self, iter: I)
[src]
impl<'a> Extend<&'a u8> for Message
[src]
fn extend<I: IntoIterator<Item = &'a u8>>(&mut self, iter: I)
[src]
impl Clone for Message
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for Message
[src]
impl Deref for Message
[src]
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.
fn index(&self, index: I) -> &Self::Output
[src]
impl<I: SliceIndex<[u8]>> IndexMut<I> for Message
[src]
impl FromIterator<u8> for Message
[src]
ⓘImportant traits for Messagefn from_iter<T>(iter: T) -> Message where
T: IntoIterator<Item = u8>,
[src]
T: IntoIterator<Item = u8>,
impl<'a> FromIterator<&'a u8> for Message
[src]
ⓘImportant traits for Messagefn from_iter<T>(iter: T) -> Message where
T: IntoIterator<Item = &'a u8>,
[src]
T: IntoIterator<Item = &'a u8>,
impl Write for Message
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn write_all(&mut self, buf: &[u8]) -> Result<()>
[src]
fn flush(&mut self) -> Result<()>
[src]
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>
1.36.0[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
1.0.0[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]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,