Struct Message

Source
pub struct Message(/* private fields */);
Expand description

Message primitive

Implementations§

Source§

impl Message

Source

pub fn new() -> Option<Self>

Creates empty message

Returns None if unable to allocate memory

Source

pub fn with_capaicty(size: usize) -> Option<Self>

Creates message with pre-allocated buffer of provided size

Returns None if unable to allocate memory

Source

pub fn dup(&self) -> Option<Self>

Creates new copy of the message.

Returns None if unable to allocate memory

Source

pub fn reserve(&mut self, capacity: usize) -> Result<(), ErrorCode>

Reserves additional space to accommodate specified capacity

Does nothing, if message already has enough space.

Returns error only if reallocation failed

Source

pub fn len(&self) -> usize

Returns length of message body

Source

pub fn capaciy(&self) -> usize

Returns capacity of message body

Source

pub fn clear(&mut self)

Clears content of the message.

Note that it is primarily sets length of body to 0. Allocated capacity remains the same.

Source

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

Shortens body length, keeping len starting elements

Has no effect if len is equal or greater to current body’s length

Source

pub fn truncate_start(&mut self, len: usize)

Shortens body length, keeping len last elements inside

Has no effect if len is equal or greater to current body’s length

Source

pub fn body(&self) -> &[u8]

Returns reference to the body content

Source

pub fn header(&self) -> &[u8]

Returns reference to the header content

Source

pub fn pop_u16(&mut self) -> Option<u16>

Extracts u16 from the end of body, encoding it into native byte order

Returns None if there is not enough space

Source

pub fn pop_u32(&mut self) -> Option<u32>

Extracts u32 from the end of body, encoding it into native byte order

Returns None if there is not enough space

Source

pub fn pop_u64(&mut self) -> Option<u64>

Extracts u64 from the end of body, encoding it into native byte order

Returns None if there is not enough space

Source

pub fn pop_front_u16(&mut self) -> Option<u16>

Extracts u16 from the start of body, encoding it into native byte order

Returns None if there is not enough space

Source

pub fn pop_front_u32(&mut self) -> Option<u32>

Extracts u32 from the start of body, encoding it into native byte order

Returns None if there is not enough space

Source

pub fn pop_front_u64(&mut self) -> Option<u64>

Extracts u64 from the start of body, encoding it into native byte order

Returns None if there is not enough space

Source

pub fn append_u16(&mut self, value: u16) -> Result<(), ErrorCode>

Appends u16 to the end of body, encoding it into network byte order

Returns Err if there is not enough space

Source

pub fn append_u32(&mut self, value: u32) -> Result<(), ErrorCode>

Appends u32 to the end of body, encoding it into network byte order

Returns Err if there is not enough space

Source

pub fn append_u64(&mut self, value: u64) -> Result<(), ErrorCode>

Appends u64 to the end of body, encoding it into network byte order

Returns Err if there is not enough space

Source

pub fn append(&mut self, bytes: &[u8]) -> Result<(), ErrorCode>

Appends bytes to the message body.

Source

pub fn insert_u16(&mut self, value: u16) -> Result<(), ErrorCode>

Inserts u16 at the start of body, encoding it into network byte order

Returns Err if there is not enough space

Source

pub fn insert_u32(&mut self, value: u32) -> Result<(), ErrorCode>

Inserts u32 at the start of body, encoding it into network byte order

Returns Err if there is not enough space

Source

pub fn insert_u64(&mut self, value: u64) -> Result<(), ErrorCode>

Inserts u64 at the start of body, encoding it into network byte order

Returns Err if there is not enough space

Source

pub fn insert(&mut self, bytes: &[u8]) -> Result<(), ErrorCode>

Inserts bytes at the start of the body.

Methods from Deref<Target = NonNull<nng_msg>>§

1.25.0 · Source

pub unsafe fn as_ref<'a>(&self) -> &'a T

Returns a shared reference to the value. If the value may be uninitialized, as_uninit_ref must be used instead.

For the mutable counterpart see as_mut.

§Safety

When calling this method, you have to ensure that the pointer is convertible to a reference.

§Examples
use std::ptr::NonNull;

let mut x = 0u32;
let ptr = NonNull::new(&mut x as *mut _).expect("ptr is null!");

let ref_x = unsafe { ptr.as_ref() };
println!("{ref_x}");
1.25.0 · Source

pub unsafe fn as_mut<'a>(&mut self) -> &'a mut T

Returns a unique reference to the value. If the value may be uninitialized, as_uninit_mut must be used instead.

For the shared counterpart see as_ref.

§Safety

When calling this method, you have to ensure that the pointer is convertible to a reference.

§Examples
use std::ptr::NonNull;

let mut x = 0u32;
let mut ptr = NonNull::new(&mut x).expect("null pointer");

let x_ref = unsafe { ptr.as_mut() };
assert_eq!(*x_ref, 0);
*x_ref += 2;
assert_eq!(*x_ref, 2);

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

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

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

impl Deref for Message

Source§

type Target = NonNull<nng_msg>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Message

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Drop for Message

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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