Array

Struct Array 

Source
pub struct Array<T, V: Pod> { /* private fields */ }
Expand description

A fixed-size array.

The size of the array is defined on the eBPF side using the bpf_map_def::max_entries field. All the entries are zero-initialized when the map is created.

§Minimum kernel version

The minimum kernel version required to use this feature is 3.19.

§Examples

use aya::maps::Array;

let mut array = Array::try_from(bpf.map_mut("ARRAY").unwrap())?;
array.set(1, 42, 0)?;
assert_eq!(array.get(&1, 0)?, 42);

Implementations§

Source§

impl<T: Borrow<MapData>, V: Pod> Array<T, V>

Source

pub fn len(&self) -> u32

Returns the number of elements in the array.

This corresponds to the value of bpf_map_def::max_entries on the eBPF side.

Source

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

Returns the value stored at the given index.

§Errors

Returns MapError::OutOfBounds if index is out of bounds, MapError::SyscallError if bpf_map_lookup_elem fails.

Source

pub fn iter(&self) -> impl Iterator<Item = Result<V, MapError>> + '_

An iterator over the elements of the array. The iterator item type is Result<V, MapError>.

Source§

impl<T: BorrowMut<MapData>, V: Pod> Array<T, V>

Source

pub fn set( &mut self, index: u32, value: impl Borrow<V>, flags: u64, ) -> Result<(), MapError>

Sets the value of the element at the given index.

§Errors

Returns MapError::OutOfBounds if index is out of bounds, MapError::SyscallError if bpf_map_update_elem fails.

Source§

impl<T: Borrow<MapData>, V: Pod> Array<T, V>

Source

pub fn pin<P: AsRef<Path>>(self, path: P) -> Result<(), PinError>

Pins the map to a BPF filesystem.

When a map is pinned it will remain loaded until the corresponding file is deleted. All parent directories in the given path must already exist.

Trait Implementations§

Source§

impl<T: Borrow<MapData>, V: Pod> IterableMap<u32, V> for Array<T, V>

Source§

fn map(&self) -> &MapData

Get a generic map handle
Source§

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

Get the value for the provided key
Source§

impl<'a, V: Pod> TryFrom<&'a Map> for Array<&'a MapData, V>

Source§

type Error = MapError

The type returned in the event of a conversion error.
Source§

fn try_from(map: &'a Map) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a, V: Pod> TryFrom<&'a mut Map> for Array<&'a mut MapData, V>

Source§

type Error = MapError

The type returned in the event of a conversion error.
Source§

fn try_from(map: &'a mut Map) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<V: Pod> TryFrom<Map> for Array<MapData, V>

Source§

type Error = MapError

The type returned in the event of a conversion error.
Source§

fn try_from(map: Map) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<T, V> Freeze for Array<T, V>
where T: Freeze,

§

impl<T, V> RefUnwindSafe for Array<T, V>

§

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

§

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

§

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

§

impl<T, V> UnwindSafe for Array<T, V>
where T: UnwindSafe, 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.