Struct Queue

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

A queue that exposes an idiomatic Rust interface to an underlying BPF queue.

Implementations§

Source§

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

Source

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

Creates a new BPF queue with entries elements. A queue works as a FIFO container: push() inserts an element to the back and pop() consumes an element from the front.

§Arguments
  • entries - The maximum number of elements in the queue.
§Example
use bpf_api::collections::Queue;

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

pub fn pop(&self) -> Result<V, Error>

Retrieves and removes the next element in the queue, if it exists.

§Example
use bpf_api::collections::Queue;

let queue = Queue::<u32>::with_capacity(10).expect("Failed to create queue");
assert!(matches!(queue.pop(), Err(_)));
Source

pub fn front(&self) -> Result<V, Error>

Retrieves next element in the queue, if it exists. This does not remove the element.

§Example
use bpf_api::collections::Queue;

let queue = Queue::<u32>::with_capacity(10).expect("Failed to create queue");
assert!(matches!(queue.front(), Err(_)));
Source

pub fn push(&self, val: V) -> Result<(), Error>

Push a new element to the back of the queue.

§Example
use bpf_api::collections::Queue;

let queue = Queue::<u32>::with_capacity(10).expect("Failed to create queue");
assert!(matches!(queue.push(100), Ok(_)));
assert!(matches!(queue.front(), Ok(100)));
assert!(matches!(queue.pop(), Ok(100)));
assert!(matches!(queue.pop(), Err(_)));
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::Queue;

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

Auto Trait Implementations§

§

impl<V> !Freeze for Queue<V>

§

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

§

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

§

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

§

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

§

impl<V> UnwindSafe for Queue<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.