Stack

Struct Stack 

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

A LIFO stack.

§Minimum kernel version

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

§Examples

use aya::maps::Stack;

let mut stack = Stack::try_from(bpf.map_mut("STACK").unwrap())?;
stack.push(42, 0)?;
stack.push(43, 0)?;
assert_eq!(stack.pop(0)?, 43);

Implementations§

Source§

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

Source

pub fn capacity(&self) -> u32

Returns the number of elements the stack can hold.

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

Source§

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

Source

pub fn pop(&mut self, flags: u64) -> Result<V, MapError>

Removes the last element and returns it.

§Errors

Returns MapError::ElementNotFound if the stack is empty, MapError::SyscallError if bpf_map_lookup_and_delete_elem fails.

Source

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

Pushes an element on the stack.

§Errors

MapError::SyscallError if bpf_map_update_elem fails.

Source§

impl<T: Borrow<MapData>, V: Pod> Stack<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<'a, V: Pod> TryFrom<&'a Map> for Stack<&'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 Stack<&'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 Stack<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 Stack<T, V>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T, V> UnwindSafe for Stack<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.