Struct Array

Source
pub struct Array<V: Copy + Default> { /* private fields */ }
Expand description

An array that exposes an idiomatic Rust interface to an underlying BPF array.

Implementations§

Source§

impl<V: Copy + Default> Array<V>

Source

pub fn with_capacity(entries: u32) -> Result<Self, Error>

Creates a new BPF array with entries elements. The kernel zero-initializes all elements on creation.

§Arguments
  • entries - The number of elements in the array.
§Example
use bpf_api::collections::Array;

let array = Array::<u32>::with_capacity(10).expect("Failed to create array");
Source

pub fn get(&self, index: u32) -> Result<V, Error>

Retrieves the value for a given element.

§Arguments
  • index - The element index to retrieve.
§Example
use bpf_api::collections::Array;

let array = Array::<u32>::with_capacity(10).expect("Failed to create array");
assert_eq!(array.get(5).expect("Failed to get element 5"), 0);
Source

pub fn set(&self, index: u32, value: V) -> Result<(), Error>

Sets the value at a given index.

§Arguments
  • index - The element index to retrieve.
  • value - The new value.
§Example
use bpf_api::collections::Array;

let array = Array::<u32>::with_capacity(10).expect("Failed to create array");
assert_eq!(array.get(5).expect("Failed to get element 5"), 0);
assert!(matches!(array.set(5, 10), Ok(_)));
assert_eq!(array.get(5).expect("Failed to get element 5"), 10);
Source

pub fn get_identifier(&self) -> u32

Retrieve the BPF identifier for this map. This is the underlying file descriptor that’s used in eBPF programs.

§Example
use bpf_api::collections::Array;

let array = Array::<u32>::with_capacity(10).expect("Failed to create array");
array.get_identifier();

Auto Trait Implementations§

§

impl<V> !Freeze for Array<V>

§

impl<V> RefUnwindSafe for Array<V>
where V: RefUnwindSafe,

§

impl<V> Send for Array<V>
where V: Send,

§

impl<V> Sync for Array<V>
where V: Sync,

§

impl<V> Unpin for Array<V>
where V: Unpin,

§

impl<V> UnwindSafe for Array<V>
where V: UnwindSafe,

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.