pub struct HashMap<K: Copy + Default + Sized, V: Copy + Default + Sized> { /* private fields */ }

Implementations

Creates a new BPF hashmap with entries elements.

Arguments
  • entries - The number of elements in the array.
Example
use bpf_api::collections::HashMap;

let hashmap = HashMap::<u32, u32>::create(10).expect("Failed to create hashmap");

Retrieves the value for a given key.

Arguments
  • key - The key associated with the value to be retrieved.
Example
use bpf_api::collections::HashMap;

let hashmap = HashMap::<u32, u32>::create(10).expect("Failed to create hashmap");
assert!(matches!(hashmap.get(1000), Err(_)));

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)));

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(_)));

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

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.