Struct NlmsgWriter

Source
pub struct NlmsgWriter<'a, H: NlmsgHeader = ()> { /* private fields */ }
๐Ÿ‘ŽDeprecated: beta features are subject to change at any time
Expand description

A writer for netlink messages

See also the crate documentation.

Implementationsยง

Sourceยง

impl<'a, H: NlmsgHeader> NlmsgWriter<'a, H>

Source

pub fn new<T: Pod + ?Sized>(buf: &'a mut T, header: H) -> Result<Self>

Creates a new writer that uses the buffer as backing storage

Source

pub fn write<T: ?Sized>(&mut self, data: &T) -> Result<()>

Writes an object to the buffer

This involves three steps:

  • The write position is aligned to the next 4 byte boundary
  • The object is written
  • The write position is advanced by the size of the object

Returns an error if the buffer does not contain enough space.

Source

pub fn nest<H2: NlmsgHeader>( &mut self, header: H2, ) -> Result<NlmsgWriter<'_, H2>>

Nests a new message within the write buffer

Returns an error if there is not enough space to write the header at the next 4 byte boundary.

When the nested writer is dropped, the behavior is as if the nested message had been written to a separate buffer and then written to this writer using Self::write.

Source

pub fn finalize(self) -> Result<&'a mut [u8]>

Sets the length field of the header to the correct value

This function returns an error if [NlmsgHeader::set_len] fails.

Trait Implementationsยง

Sourceยง

impl<'a, H: NlmsgHeader> Drop for NlmsgWriter<'a, H>

Sourceยง

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementationsยง

ยง

impl<'a, H> Freeze for NlmsgWriter<'a, H>
where H: Freeze,

ยง

impl<'a, H> RefUnwindSafe for NlmsgWriter<'a, H>
where H: RefUnwindSafe,

ยง

impl<'a, H> Send for NlmsgWriter<'a, H>
where H: Send,

ยง

impl<'a, H> Sync for NlmsgWriter<'a, H>
where H: Sync,

ยง

impl<'a, H> Unpin for NlmsgWriter<'a, H>
where H: Unpin,

ยง

impl<'a, H = ()> !UnwindSafe for NlmsgWriter<'a, H>

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, 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.