Struct NetlinkBitArray

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

A bit array meant to be compatible with the bit array returned by the NETLINK_LIST_MEMBERSHIPS socket operation on netlink sockets.

Implementations§

Source§

impl NetlinkBitArray

bittest/bitset instrinsics are not stable in Rust so this needs to be implemented this way.

Source

pub fn new(bit_len: usize) -> Self

Create a new bit array.

This method will round bit_len up to the nearest multiple of size_of::<u32>().

Source

pub fn resize_bits(&mut self, bit_len: usize)

Resize the underlying vector to have enough space for the nearest multiple of size_of::<u32>() rounded up.

Source

pub fn resize(&mut self, bytes: usize)

Resize the underlying vector to have enough space for the nearest multiple of size_of::<BitArrayType>().

Source

pub fn is_set(&self, n: usize) -> bool

Returns true if the nth bit is set.

Source

pub fn set(&mut self, n: usize)

Set the nth bit.

Source

pub fn to_vec(&self) -> Vec<u32>

Get a vector representation of all of the bit positions set to 1 in this bit array.

§Example
use neli::utils::NetlinkBitArray;

let mut array = NetlinkBitArray::new(24);
array.set(4);
array.set(7);
array.set(23);
assert_eq!(array.to_vec(), vec![4, 7, 23]);
Source

pub fn len_bits(&self) -> usize

Return the number of bits that can be contained in this bit array.

Source

pub fn len(&self) -> usize

Return the length in bytes for this bit array.

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