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;
use std::convert::TryFrom;
let mut array = Array::try_from(bpf.map_mut("ARRAY")?)?;
array.set(1, 42, 0)?;
assert_eq!(array.get(&1, 0)?, 42);
Implementations
sourceimpl<T: Deref<Target = Map>, V: Pod> Array<T, V>
impl<T: Deref<Target = Map>, V: Pod> Array<T, V>
sourcepub fn len(&self) -> u32
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.
sourcepub fn get(&self, index: &u32, flags: u64) -> Result<V, MapError>
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.
sourceimpl<T: Deref<Target = Map> + DerefMut<Target = Map>, V: Pod> Array<T, V>
impl<T: Deref<Target = Map> + DerefMut<Target = Map>, V: Pod> Array<T, V>
sourcepub fn set(&mut self, index: u32, value: V, flags: u64) -> Result<(), MapError>
pub fn set(&mut self, index: u32, value: 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.
Trait Implementations
Auto Trait Implementations
impl<T, V> RefUnwindSafe for Array<T, V> where
T: RefUnwindSafe,
V: RefUnwindSafe,
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more