LinearMapInner

Struct LinearMapInner 

Source
pub struct LinearMapInner<K, V, S: LinearMapStorage<K, V> + ?Sized> { /* private fields */ }
Expand description

Base struct for LinearMap and LinearMapView

Implementations§

Source§

impl<K, V, const N: usize> LinearMapInner<K, V, VecStorageInner<[MaybeUninit<(K, V)>; N]>>

Source

pub const fn new() -> Self

Creates an empty LinearMap.

§Examples
use heapless::LinearMap;

// allocate the map on the stack
let mut map: LinearMap<&str, isize, 8> = LinearMap::new();

// allocate the map in a static variable
static mut MAP: LinearMap<&str, isize, 8> = LinearMap::new();
Source§

impl<K, V, S: LinearMapStorage<K, V> + ?Sized> LinearMapInner<K, V, S>
where K: Eq,

Source

pub fn as_view(&self) -> &LinearMapView<K, V>

Get a reference to the LinearMap, erasing the N const-generic.

Source

pub fn as_mut_view(&mut self) -> &mut LinearMapView<K, V>

Get a mutable reference to the LinearMap, erasing the N const-generic.

Source

pub fn capacity(&self) -> usize

Returns the number of elements that the map can hold.

Computes in O(1) time.

§Examples
use heapless::LinearMap;

let map: LinearMap<&str, isize, 8> = LinearMap::new();
assert_eq!(map.capacity(), 8);
Source

pub fn clear(&mut self)

Clears the map, removing all key-value pairs.

Computes in O(1) time.

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert(1, "a").unwrap();
map.clear();
assert!(map.is_empty());
Source

pub fn contains_key(&self, key: &K) -> bool

Returns true if the map contains a value for the specified key.

Computes in O(n) time.

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert(1, "a").unwrap();
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Eq + ?Sized,

Returns a reference to the value corresponding to the key.

Computes in O(n) time.

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert(1, "a").unwrap();
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Eq + ?Sized,

Returns a mutable reference to the value corresponding to the key.

Computes in O(n) time.

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert(1, "a").unwrap();
if let Some(x) = map.get_mut(&1) {
    *x = "b";
}
assert_eq!(map[&1], "b");
Source

pub fn len(&self) -> usize

Returns the number of elements in this map.

Computes in O(1) time.

§Examples
use heapless::LinearMap;

let mut a: LinearMap<_, _, 8> = LinearMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a").unwrap();
assert_eq!(a.len(), 1);
Source

pub fn insert(&mut self, key: K, value: V) -> Result<Option<V>, (K, V)>

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned.

Computes in O(n) time

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
assert_eq!(map.insert(37, "a").unwrap(), None);
assert_eq!(map.is_empty(), false);

map.insert(37, "b").unwrap();
assert_eq!(map.insert(37, "c").unwrap(), Some("b"));
assert_eq!(map[&37], "c");
Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Computes in O(1) time.

§Examples
use heapless::LinearMap;

let mut a: LinearMap<_, _, 8> = LinearMap::new();
assert!(a.is_empty());
a.insert(1, "a").unwrap();
assert!(!a.is_empty());
Source

pub fn is_full(&self) -> bool

Returns true if the map is full.

Computes in O(1) time.

§Examples
use heapless::LinearMap;

let mut a: LinearMap<_, _, 4> = LinearMap::new();
assert!(!a.is_full());
a.insert(1, "a").unwrap();
a.insert(2, "b").unwrap();
a.insert(3, "c").unwrap();
a.insert(4, "d").unwrap();
assert!(a.is_full());
Source

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

An iterator visiting all key-value pairs in arbitrary order.

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert("a", 1).unwrap();
map.insert("b", 2).unwrap();
map.insert("c", 3).unwrap();

for (key, val) in map.iter() {
    println!("key: {} val: {}", key, val);
}
Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values.

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert("a", 1).unwrap();
map.insert("b", 2).unwrap();
map.insert("c", 3).unwrap();

// Update all values
for (_, val) in map.iter_mut() {
    *val = 2;
}

for (key, val) in &map {
    println!("key: {} val: {}", key, val);
}
Source

pub fn keys(&self) -> impl Iterator<Item = &K>

An iterator visiting all keys in arbitrary order.

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert("a", 1).unwrap();
map.insert("b", 2).unwrap();
map.insert("c", 3).unwrap();

for key in map.keys() {
    println!("{}", key);
}
Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Eq + ?Sized,

Removes a key from the map, returning the value at the key if the key was previously in the map.

Computes in O(n) time

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert(1, "a").unwrap();
assert_eq!(map.remove(&1), Some("a"));
assert_eq!(map.remove(&1), None);
Source

pub fn values(&self) -> impl Iterator<Item = &V>

An iterator visiting all values in arbitrary order.

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert("a", 1).unwrap();
map.insert("b", 2).unwrap();
map.insert("c", 3).unwrap();

for val in map.values() {
    println!("{}", val);
}
Source

pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>

An iterator visiting all values mutably in arbitrary order.

§Examples
use heapless::LinearMap;

let mut map: LinearMap<_, _, 8> = LinearMap::new();
map.insert("a", 1).unwrap();
map.insert("b", 2).unwrap();
map.insert("c", 3).unwrap();

for val in map.values_mut() {
    *val += 10;
}

for val in map.values() {
    println!("{}", val);
}

Trait Implementations§

Source§

impl<K, V, S: LinearMapStorage<K, V> + ?Sized> Debug for LinearMapInner<K, V, S>
where K: Eq + Debug, V: Debug,

Source§

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

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

impl<K, V, Q, S: LinearMapStorage<K, V> + ?Sized> Index<&Q> for LinearMapInner<K, V, S>
where K: Borrow<Q> + Eq, Q: Eq + ?Sized,

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, key: &Q) -> &V

Performs the indexing (container[index]) operation. Read more
Source§

impl<K, V, Q, S: LinearMapStorage<K, V> + ?Sized> IndexMut<&Q> for LinearMapInner<K, V, S>
where K: Borrow<Q> + Eq, Q: Eq + ?Sized,

Source§

fn index_mut(&mut self, key: &Q) -> &mut V

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, K, V, S: LinearMapStorage<K, V> + ?Sized> IntoIterator for &'a LinearMapInner<K, V, S>
where K: Eq,

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, 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<K, V1, V2, S1: LinearMapStorage<K, V1> + ?Sized, S2: LinearMapStorage<K, V2> + ?Sized> PartialEq<LinearMapInner<K, V2, S2>> for LinearMapInner<K, V1, S1>
where K: Eq, V1: PartialEq<V2>,

Source§

fn eq(&self, other: &LinearMapInner<K, V2, S2>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, V, S: LinearMapStorage<K, V> + ?Sized> Eq for LinearMapInner<K, V, S>
where K: Eq, V: PartialEq,

Auto Trait Implementations§

§

impl<K, V, S> Freeze for LinearMapInner<K, V, S>
where S: Freeze + ?Sized,

§

impl<K, V, S> RefUnwindSafe for LinearMapInner<K, V, S>

§

impl<K, V, S> Send for LinearMapInner<K, V, S>
where S: Send + ?Sized, K: Send, V: Send,

§

impl<K, V, S> Sync for LinearMapInner<K, V, S>
where S: Sync + ?Sized, K: Sync, V: Sync,

§

impl<K, V, S> Unpin for LinearMapInner<K, V, S>
where S: Unpin + ?Sized, K: Unpin, V: Unpin,

§

impl<K, V, S> UnwindSafe for LinearMapInner<K, V, S>
where S: UnwindSafe + ?Sized, 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.