pub struct ArrayMap {
    pub base: Map,
}

Fields

base: Map

Implementations

Create a new ArrayMap

Calling new will create a new BPF_MAP_TYPE_ARRAY map. It stores some meta data to track it. The array map supports read and write operations to access the members of the map

Safety

The value_size you pass in needs to match exactly with the size of the struct/type used by any other BPF program that might be using this map. Any T you use in subsequent read() and write() calls needs to match exactly (e.g., with #[repr(C)]) with the struct/type used by the BPF program as well. Additionally, std::mem::size_of::<T>() must match the given value_size here exactly. If this conditions are not met, the ArrayMap behavior is undefined.

Examples
use oxidebpf::ArrayMap;
let map: ArrayMap = unsafe {ArrayMap::new(
   "mymap",
   std::mem::size_of::<u64>() as u32,
   1024,
).expect("Failed to create map") };

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Reads an index from a map of type BPF_MAP_TYPE_ARRAY

Initiates a read from key. Read verifies that the map has been initialized. The value returned will be of the same type that was used when the ArrayMap was created

NOTE: This method calls will read a certain amount of memory based on what the size of T is. Make sure that T matches the type of the value (e.g., with #[repr(C)]) that is being used in the map.

Example
use oxidebpf::{ArrayMap, RWMap};

// this is safe because we are reading and writing a u64, and the value_size we
// pass into new() is a u64

unsafe {
    let map: ArrayMap = ArrayMap::new(
       "mymap",
       std::mem::size_of::<u64>() as u32,
       1024,
    ).expect("Failed to create map");
    let _ = map.write(0, 12345u64);
    assert_eq!(
        12345u64,
        unsafe { map.read(0).expect("Failed to read value from map") }
    );
}

Writes an index to and index of a map of type BPF_MAP_TYPE_ARRAY

Initiates a write to key of value. The value needs to match the array type that was used when the map was created

NOTE: This method calls will write a certain amount of memory based on what the size of T is. Make sure that T matches the type of the value (e.g., with #[repr(C)]) that is being used in the map.

Example
use oxidebpf::{ArrayMap, RWMap};

// this is safe because we are reading and writing a u64, and the value_size we
// pass into new() is a u64

unsafe {
    let map: ArrayMap = ArrayMap::new(
       "mymap",
       std::mem::size_of::<u64>() as u32,
       1024,
    ).expect("Failed to create map");
    let _ = map.write(0, 12345u64);
    assert_eq!(
        12345u64,
        map.read(0).expect("Failed to read value from map")
    );
}

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

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.