Skip to main content

HashMap

Struct HashMap 

Source
pub struct HashMap<T, K, V> { /* private fields */ }
Expand description

A hash map that can be shared between eBPF programs and user space.

§Minimum kernel version

The minimum kernel version required to use this feature is 3.19.

§Examples

use aya::maps::HashMap;

let mut redirect_ports = HashMap::try_from(bpf.map_mut("REDIRECT_PORTS").unwrap())?;

// redirect port 80 to 8080
redirect_ports.insert(80, 8080, 0);
// redirect port 443 to 8443
redirect_ports.insert(443, 8443, 0);

Implementations§

Source§

impl<T: Borrow<MapData>, K: Pod, V: Pod> HashMap<T, K, V>

Source

pub fn get(&self, key: &K, flags: u64) -> Result<V, MapError>

Returns a copy of the value associated with the key.

Source

pub fn iter(&self) -> MapIter<'_, K, V, Self>

An iterator visiting all key-value pairs in arbitrary order. The iterator item type is Result<(K, V), MapError>.

Source

pub fn keys(&self) -> MapKeys<'_, K>

An iterator visiting all keys in arbitrary order. The iterator element type is Result<K, MapError>.

Source§

impl<T: BorrowMut<MapData>, K: Pod, V: Pod> HashMap<T, K, V>

Source

pub fn insert( &mut self, key: impl Borrow<K>, value: impl Borrow<V>, flags: u64, ) -> Result<(), MapError>

Inserts a key-value pair into the map.

Source

pub fn remove(&mut self, key: &K) -> Result<(), MapError>

Removes a key from the map.

Source§

impl<T: Borrow<MapData>, K: Pod, V: Pod> HashMap<T, K, V>

Source

pub fn pin<P: AsRef<Path>>(self, path: P) -> Result<(), PinError>

Pins the map to a BPF filesystem.

When a map is pinned it will remain loaded until the corresponding file is deleted. All parent directories in the given path must already exist.

Source§

impl<K: Pod, V: Pod> HashMap<MapData, K, V>

Source

pub fn create(max_entries: u32, flags: u32) -> Result<Self, MapError>

Creates a standalone map with the given max_entries capacity and flags.

Trait Implementations§

Source§

impl<T: Debug, K: Debug, V: Debug> Debug for HashMap<T, K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: Borrow<MapData>, K: Pod, V: Pod> IntoIterator for &'a HashMap<T, K, V>

Source§

type Item = Result<(K, V), MapError>

The type of the elements being iterated over.
Source§

type IntoIter = MapIter<'a, K, V, HashMap<T, K, V>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Borrow<MapData>, K: Pod, V: Pod> IterableMap<K, V> for HashMap<T, K, V>

Source§

fn map(&self) -> &MapData

Get a generic map handle
Source§

fn get(&self, key: &K) -> Result<V, MapError>

Get the value for the provided key
Source§

impl<'a, K: Pod, V: Pod> TryFrom<&'a Map> for HashMap<&'a MapData, K, V>

Source§

type Error = MapError

The type returned in the event of a conversion error.
Source§

fn try_from(map: &'a Map) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a, K: Pod, V: Pod> TryFrom<&'a mut Map> for HashMap<&'a mut MapData, K, V>

Source§

type Error = MapError

The type returned in the event of a conversion error.
Source§

fn try_from(map: &'a mut Map) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<K: Pod, V: Pod> TryFrom<Map> for HashMap<MapData, K, V>

Source§

type Error = MapError

The type returned in the event of a conversion error.
Source§

fn try_from(map: Map) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<T, K, V> Freeze for HashMap<T, K, V>
where T: Freeze,

§

impl<T, K, V> RefUnwindSafe for HashMap<T, K, V>

§

impl<T, K, V> Send for HashMap<T, K, V>
where T: Send, K: Send, V: Send,

§

impl<T, K, V> Sync for HashMap<T, K, V>
where T: Sync, K: Sync, V: Sync,

§

impl<T, K, V> Unpin for HashMap<T, K, V>
where T: Unpin, K: Unpin, V: Unpin,

§

impl<T, K, V> UnsafeUnpin for HashMap<T, K, V>
where T: UnsafeUnpin,

§

impl<T, K, V> UnwindSafe for HashMap<T, K, V>
where T: UnwindSafe, K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> FromMapData for T
where T: FromMapData,

Source§

impl<T> InnerMap for T
where T: InnerMap,