Struct bpf_api::collections::HashMap
source · [−]Implementations
sourceimpl<K: Copy + Default + Sized, V: Copy + Default + Sized> HashMap<K, V>
impl<K: Copy + Default + Sized, V: Copy + Default + Sized> HashMap<K, V>
sourcepub fn set(&self, key: K, val: V) -> Result<(), Error>
pub fn set(&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>::create(10).expect("Failed to create hashmap");
assert!(matches!(hashmap.get(1000), Err(_)));
assert!(matches!(hashmap.set(1000, 0xdeadbeef), Ok(_)));
assert!(matches!(hashmap.get(1000), Ok(0xdeadbeef)));
sourcepub fn del(&self, key: K) -> Result<(), Error>
pub fn del(&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>::create(10).expect("Failed to create hashmap");
assert!(matches!(hashmap.get(1000), Err(_)));
assert!(matches!(hashmap.set(1000, 0xdeadbeef), Ok(_)));
assert!(matches!(hashmap.get(1000), Ok(0xdeadbeef)));
assert!(matches!(hashmap.del(1000), Ok(_)));
assert!(matches!(hashmap.del(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>::create(10).expect("Failed to create array");
hashmap.get_identifier();
Auto Trait Implementations
impl<K, V> RefUnwindSafe for HashMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for HashMap<K, V>where
K: Send,
V: Send,
impl<K, V> Sync for HashMap<K, V>where
K: Sync,
V: Sync,
impl<K, V> Unpin for HashMap<K, V>where
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for HashMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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