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>
impl<V: Copy + Default> Queue<V>
Sourcepub fn with_capacity(entries: u32) -> Result<Self, Error>
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");
Sourcepub fn pop(&self) -> Result<V, Error>
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(_)));
Sourcepub fn front(&self) -> Result<V, Error>
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(_)));
Sourcepub fn push(&self, val: V) -> Result<(), Error>
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(_)));
Sourcepub fn get_identifier(&self) -> u32
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more