pub struct Message(/* private fields */);
Expand description
Message primitive
Implementations§
Source§impl Message
impl Message
Sourcepub fn with_capaicty(size: usize) -> Option<Self>
pub fn with_capaicty(size: usize) -> Option<Self>
Creates message with pre-allocated buffer of provided size
Returns None
if unable to allocate memory
Sourcepub fn dup(&self) -> Option<Self>
pub fn dup(&self) -> Option<Self>
Creates new copy of the message.
Returns None
if unable to allocate memory
Sourcepub fn reserve(&mut self, capacity: usize) -> Result<(), ErrorCode>
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
Sourcepub fn clear(&mut self)
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.
Sourcepub fn truncate(&mut self, len: usize)
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
Sourcepub fn truncate_start(&mut self, len: usize)
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
Sourcepub fn pop_u16(&mut self) -> Option<u16>
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
Sourcepub fn pop_u32(&mut self) -> Option<u32>
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
Sourcepub fn pop_u64(&mut self) -> Option<u64>
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
Sourcepub fn pop_front_u16(&mut self) -> Option<u16>
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
Sourcepub fn pop_front_u32(&mut self) -> Option<u32>
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
Sourcepub fn pop_front_u64(&mut self) -> Option<u64>
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
Sourcepub fn append_u16(&mut self, value: u16) -> Result<(), ErrorCode>
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
Sourcepub fn append_u32(&mut self, value: u32) -> Result<(), ErrorCode>
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
Sourcepub fn append_u64(&mut self, value: u64) -> Result<(), ErrorCode>
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
Sourcepub fn append(&mut self, bytes: &[u8]) -> Result<(), ErrorCode>
pub fn append(&mut self, bytes: &[u8]) -> Result<(), ErrorCode>
Appends bytes
to the message body.
Sourcepub fn insert_u16(&mut self, value: u16) -> Result<(), ErrorCode>
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
Sourcepub fn insert_u32(&mut self, value: u32) -> Result<(), ErrorCode>
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
Methods from Deref<Target = NonNull<nng_msg>>§
1.25.0 · Sourcepub unsafe fn as_ref<'a>(&self) -> &'a T
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 · Sourcepub unsafe fn as_mut<'a>(&mut self) -> &'a mut T
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);