pub struct HashMap<K: Copy + Default, V: Copy + Default> { /* private fields */ }
Expand description
A hashmap that exposes an idiomatic Rust interface to an underlying BPF hashmap.
Implementations§
Source§impl<K: Copy + Default, V: Copy + Default> HashMap<K, V>
impl<K: Copy + Default, V: Copy + Default> HashMap<K, V>
Sourcepub fn with_capacity(entries: u32) -> Result<Self, Error>
pub fn with_capacity(entries: u32) -> Result<Self, Error>
Sourcepub fn insert(&self, key: K, val: V) -> Result<(), Error>
pub fn insert(&self, key: K, val: V) -> Result<(), Error>
Sets the value for a given key.
§Arguments
key
- The key associated with the value to be set.value
- The new value.
§Example
use bpf_api::collections::HashMap;
let hashmap = HashMap::<u32, u32>::with_capacity(10).expect("Failed to create hashmap");
assert!(matches!(hashmap.get(1000), Err(_)));
assert!(matches!(hashmap.insert(1000, 0xdeadbeef), Ok(_)));
assert!(matches!(hashmap.get(1000), Ok(0xdeadbeef)));
Sourcepub fn remove(&self, key: K) -> Result<(), Error>
pub fn remove(&self, key: K) -> Result<(), Error>
Deletes an entry from the hash map given a key.
§Arguments
key
- The key of the entry to be deleted.
§Example
use bpf_api::collections::HashMap;
let hashmap = HashMap::<u32, u32>::with_capacity(10).expect("Failed to create hashmap");
assert!(matches!(hashmap.get(1000), Err(_)));
assert!(matches!(hashmap.insert(1000, 0xdeadbeef), Ok(_)));
assert!(matches!(hashmap.get(1000), Ok(0xdeadbeef)));
assert!(matches!(hashmap.remove(1000), Ok(_)));
assert!(matches!(hashmap.remove(1000), 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::HashMap;
let hashmap = HashMap::<u32, u32>::with_capacity(10).expect("Failed to create hashmap");
hashmap.get_identifier();
Auto Trait Implementations§
impl<K, V> !Freeze for HashMap<K, V>
impl<K, V> RefUnwindSafe for HashMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for HashMap<K, V>
impl<K, V> Sync for HashMap<K, V>
impl<K, V> Unpin for HashMap<K, V>
impl<K, V> UnwindSafe for HashMap<K, V>where
K: UnwindSafe,
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