libbpf_rs

Trait MapCore

Source
pub trait MapCore:
    Debug
    + AsFd
    + Sealed {
Show 15 methods // Required methods fn name(&self) -> &OsStr; fn map_type(&self) -> MapType; fn key_size(&self) -> u32; fn value_size(&self) -> u32; // Provided methods fn info(&self) -> Result<MapInfo> { ... } fn keys(&self) -> MapKeyIter<'_> { ... } fn lookup(&self, key: &[u8], flags: MapFlags) -> Result<Option<Vec<u8>>> { ... } fn lookup_bloom_filter(&self, value: &[u8]) -> Result<bool> { ... } fn lookup_percpu( &self, key: &[u8], flags: MapFlags, ) -> Result<Option<Vec<Vec<u8>>>> { ... } fn delete(&self, key: &[u8]) -> Result<()> { ... } fn delete_batch( &self, keys: &[u8], count: u32, elem_flags: MapFlags, flags: MapFlags, ) -> Result<()> { ... } fn lookup_and_delete(&self, key: &[u8]) -> Result<Option<Vec<u8>>> { ... } fn update(&self, key: &[u8], value: &[u8], flags: MapFlags) -> Result<()> { ... } fn update_batch( &self, keys: &[u8], values: &[u8], count: u32, elem_flags: MapFlags, flags: MapFlags, ) -> Result<()> { ... } fn update_percpu( &self, key: &[u8], values: &[Vec<u8>], flags: MapFlags, ) -> Result<()> { ... }
}
Expand description

A trait representing core functionality common to fully initialized maps.

Required Methods§

Source

fn name(&self) -> &OsStr

Retrieve the map’s name.

Source

fn map_type(&self) -> MapType

Retrieve type of the map.

Source

fn key_size(&self) -> u32

Retrieve the size of the map’s keys.

Source

fn value_size(&self) -> u32

Retrieve the size of the map’s values.

Provided Methods§

Source

fn info(&self) -> Result<MapInfo>

Fetch extra map information

Source

fn keys(&self) -> MapKeyIter<'_>

Returns an iterator over keys in this map

Note that if the map is not stable (stable meaning no updates or deletes) during iteration, iteration can skip keys, restart from the beginning, or duplicate keys. In other words, iteration becomes unpredictable.

Source

fn lookup(&self, key: &[u8], flags: MapFlags) -> Result<Option<Vec<u8>>>

Returns map value as Vec of u8.

key must have exactly Self::key_size() elements.

If the map is one of the per-cpu data structures, the function Self::lookup_percpu() must be used. If the map is of type bloom_filter the function Self::lookup_bloom_filter() must be used

Source

fn lookup_bloom_filter(&self, value: &[u8]) -> Result<bool>

Returns if the given value is likely present in bloom_filter as bool.

value must have exactly Self::value_size() elements.

Source

fn lookup_percpu( &self, key: &[u8], flags: MapFlags, ) -> Result<Option<Vec<Vec<u8>>>>

Returns one value per cpu as Vec of Vec of u8 for per per-cpu maps.

For normal maps, Self::lookup() must be used.

Source

fn delete(&self, key: &[u8]) -> Result<()>

Deletes an element from the map.

key must have exactly Self::key_size() elements.

Source

fn delete_batch( &self, keys: &[u8], count: u32, elem_flags: MapFlags, flags: MapFlags, ) -> Result<()>

Deletes many elements in batch mode from the map.

keys must have exactly Self::key_size() * count elements.

Source

fn lookup_and_delete(&self, key: &[u8]) -> Result<Option<Vec<u8>>>

Same as Self::lookup() except this also deletes the key from the map.

Note that this operation is currently only implemented in the kernel for MapType::Queue and MapType::Stack.

key must have exactly Self::key_size() elements.

Source

fn update(&self, key: &[u8], value: &[u8], flags: MapFlags) -> Result<()>

Update an element.

key must have exactly Self::key_size() elements. value must have exactly Self::value_size() elements.

For per-cpu maps, Self::update_percpu() must be used.

Source

fn update_batch( &self, keys: &[u8], values: &[u8], count: u32, elem_flags: MapFlags, flags: MapFlags, ) -> Result<()>

Updates many elements in batch mode in the map

keys must have exactly Self::key_size() * count elements. values must have exactly Self::key_size() * count elements.

Source

fn update_percpu( &self, key: &[u8], values: &[Vec<u8>], flags: MapFlags, ) -> Result<()>

Update an element in an per-cpu map with one value per cpu.

key must have exactly Self::key_size() elements. value must have one element per cpu (see num_possible_cpus) with exactly Self::value_size() elements each.

For per-cpu maps, Self::update_percpu() must be used.

Implementors§

Source§

impl MapCore for MapHandle

Source§

impl<T> MapCore for MapImpl<'_, T>
where T: Debug,