Struct fixed_map::map::Map

source ·
pub struct Map<K, V>
where K: Key,
{ /* private fields */ }
Expand description

A fixed map with storage specialized through the Key trait.

§Examples

use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum Part {
    One,
    Two,
}

#[derive(Clone, Copy, Key)]
enum MyKey {
    Simple,
    Composite(Part),
    String(&'static str),
    Number(u32),
    Singleton(()),
    Option(Option<Part>),
    Boolean(bool),
}

let mut map = Map::new();

map.insert(MyKey::Simple, 1);
map.insert(MyKey::Composite(Part::One), 2);
map.insert(MyKey::String("foo"), 3);
map.insert(MyKey::Number(1), 4);
map.insert(MyKey::Singleton(()), 5);
map.insert(MyKey::Option(None), 6);
map.insert(MyKey::Option(Some(Part::One)), 7);
map.insert(MyKey::Boolean(true), 8);

assert_eq!(map.get(MyKey::Simple), Some(&1));
assert_eq!(map.get(MyKey::Composite(Part::One)), Some(&2));
assert_eq!(map.get(MyKey::Composite(Part::Two)), None);
assert_eq!(map.get(MyKey::String("foo")), Some(&3));
assert_eq!(map.get(MyKey::String("bar")), None);
assert_eq!(map.get(MyKey::Number(1)), Some(&4));
assert_eq!(map.get(MyKey::Number(2)), None);
assert_eq!(map.get(MyKey::Singleton(())), Some(&5));
assert_eq!(map.get(MyKey::Option(None)), Some(&6));
assert_eq!(map.get(MyKey::Option(Some(Part::One))), Some(&7));
assert_eq!(map.get(MyKey::Option(Some(Part::Two))), None);
assert_eq!(map.get(MyKey::Boolean(true)), Some(&8));
assert_eq!(map.get(MyKey::Boolean(false)), None);

Storing references:

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut map = Map::new();
let a = 42u32;

map.insert(MyKey::First, &a);

assert_eq!(map.values().cloned().collect::<Vec<_>>(), vec![&42u32]);

Implementations§

source§

impl<K, V> Map<K, V>
where K: Key,

A map implementation that uses fixed storage.

§Examples

use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    One,
    Two,
}

let mut m = Map::new();
m.insert(MyKey::One, 1);

assert_eq!(m.get(MyKey::One), Some(&1));
assert_eq!(m.get(MyKey::Two), None);

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum Part {
    A,
    B,
}

#[derive(Clone, Copy, Key)]
enum MyKey {
    Simple,
    Composite(Part),
}

let mut m = Map::new();
m.insert(MyKey::Simple, 1);
m.insert(MyKey::Composite(Part::A), 2);

assert_eq!(m.get(MyKey::Simple), Some(&1));
assert_eq!(m.get(MyKey::Composite(Part::A)), Some(&2));
assert_eq!(m.get(MyKey::Composite(Part::B)), None);
source

pub fn new() -> Map<K, V>

Creates an empty Map.

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    One,
    Two,
}

let mut map: Map<MyKey, i32> = Map::new();
source

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

An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (K, &'a V).

§Examples
use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
enum MyKey {
    One,
    Two,
    Three,
}

let mut map = Map::new();
map.insert(MyKey::One, 1);
map.insert(MyKey::Two, 2);

assert_eq!(map.iter().collect::<Vec<_>>(), vec![(MyKey::One, &1), (MyKey::Two, &2)]);
source

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

An iterator visiting all keys in arbitrary order. The iterator element type is K.

§Examples
use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
pub enum MyKey {
    First,
    Second,
    Third,
}

let mut map = Map::new();
map.insert(MyKey::First, 1);
map.insert(MyKey::Second, 2);

assert!(map.keys().eq([MyKey::First, MyKey::Second]));
assert!(map.keys().rev().eq([MyKey::Second, MyKey::First]));

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
pub enum MyKey {
    First,
    Second(bool),
    Third,
}

let mut map = Map::new();
map.insert(MyKey::First, 1);
map.insert(MyKey::Second(false), 2);

dbg!(map.keys().collect::<Vec<_>>());

assert!(map.keys().eq([MyKey::First, MyKey::Second(false)]));
assert!(map.keys().rev().eq([MyKey::Second(false), MyKey::First]));
source

pub fn values(&self) -> Values<'_, K, V>

An iterator visiting all values in arbitrary order. The iterator element type is &'a V.

§Examples
use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
pub enum MyKey {
    First,
    Second,
    Third,
}

let mut map = Map::new();
map.insert(MyKey::First, 1);
map.insert(MyKey::Second, 2);

assert!(map.values().copied().eq([1, 2]));
assert!(map.values().rev().copied().eq([2, 1]));

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
pub enum MyKey {
    First(bool),
    Second,
    Third,
}

let mut map = Map::new();
map.insert(MyKey::First(false), 1);
map.insert(MyKey::Second, 2);

assert!(map.values().copied().eq([1, 2]));
assert!(map.values().rev().copied().eq([2, 1]));
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. The iterator element type is (K, &'a mut V).

§Examples
use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
enum MyKey {
    First,
    Second,
}

let mut map = Map::new();
map.insert(MyKey::First, 1);
map.insert(MyKey::Second, 2);

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

assert!(map.iter().eq([(MyKey::First, &2), (MyKey::Second, &4)]));

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut map = Map::new();
map.insert(MyKey::First(true), 1);
map.insert(MyKey::Second, 2);

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

assert!(map.iter().eq([(MyKey::First(true), &2), (MyKey::Second, &4)]));
source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

An iterator visiting all values mutably in arbitrary order. The iterator element type is &'a mut V.

§Examples
use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
pub enum MyKey {
    First,
    Second,
}

let mut map = Map::new();
map.insert(MyKey::First, 2);
map.insert(MyKey::Second, 5);

for (index, val) in map.values_mut().enumerate() {
    *val *= index + 1;
}

assert!(map.values().copied().eq([2, 10]));

let mut map = Map::new();
map.insert(MyKey::First, 2);
map.insert(MyKey::Second, 5);

for (index, val) in map.values_mut().rev().enumerate() {
    *val *= index + 1;
}

assert!(map.values().copied().eq([4, 5]));

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
pub enum MyKey {
    First(bool),
    Second,
}

let mut map = Map::new();
map.insert(MyKey::First(false), 2);
map.insert(MyKey::Second, 5);

for (index, val) in map.values_mut().enumerate() {
    *val *= index + 1;
}

assert!(map.values().copied().eq([2, 10]));

let mut map = Map::new();
map.insert(MyKey::First(false), 2);
map.insert(MyKey::Second, 5);

for (index, val) in map.values_mut().rev().enumerate() {
    *val *= index + 1;
}

assert!(map.values().copied().eq([4, 5]));
source

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

Returns true if the map currently contains the given key.

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut map = Map::new();
map.insert(MyKey::First, "a");
assert_eq!(map.contains_key(MyKey::First), true);
assert_eq!(map.contains_key(MyKey::Second), false);
source

pub fn get(&self, key: K) -> Option<&V>

Returns a reference to the value corresponding to the key.

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut map = Map::new();
map.insert(MyKey::First, "a");
assert_eq!(map.get(MyKey::First).copied(), Some("a"));
assert_eq!(map.get(MyKey::Second), None);

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut map = Map::new();
map.insert(MyKey::First(true), "a");
assert_eq!(map.get(MyKey::First(true)).copied(), Some("a"));
assert_eq!(map.get(MyKey::Second), None);
source

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

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

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut map = Map::new();
map.insert(MyKey::First, "a");

if let Some(x) = map.get_mut(MyKey::First) {
    *x = "b";
}

assert_eq!(map.get(MyKey::First).copied(), Some("b"));

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First(bool),
    Second(()),
    Third,
}

let mut map = Map::new();
map.insert(MyKey::First(true), "a");

if let Some(x) = map.get_mut(MyKey::First(true)) {
    *x = "b";
}

assert_eq!(map.get(MyKey::First(true)).copied(), Some("b"));
source

pub fn insert(&mut self, key: K, value: V) -> Option<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.

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    One,
    Two,
}

let mut map = Map::new();
assert_eq!(map.insert(MyKey::One, "a"), None);
assert_eq!(map.is_empty(), false);

map.insert(MyKey::Two, "b");
assert_eq!(map.insert(MyKey::Two, "c"), Some("b"));
assert_eq!(map.get(MyKey::Two), Some(&"c"));
source

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

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

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    One,
    Two,
}

let mut map = Map::new();
map.insert(MyKey::One, "a");
assert_eq!(map.remove(MyKey::One), Some("a"));
assert_eq!(map.remove(MyKey::One), None);
source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(K, &mut V) -> bool,

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) for which f(k, &mut v) returns false. The elements are visited in unsorted (and unspecified) order.

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut map: Map<MyKey, i32> = Map::new();

map.insert(MyKey::First, 42);
map.insert(MyKey::Second, -10);

map.retain(|k, v| *v > 0);

assert_eq!(map.len(), 1);
assert_eq!(map.get(MyKey::First), Some(&42));
assert_eq!(map.get(MyKey::Second), None);

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut map: Map<MyKey, i32> = Map::new();

map.insert(MyKey::First(true), 42);
map.insert(MyKey::First(false), -31);
map.insert(MyKey::Second, 100);

let mut other = map.clone();
assert_eq!(map.len(), 3);

map.retain(|k, v| *v > 0);

assert_eq!(map.len(), 2);
assert_eq!(map.get(MyKey::First(true)), Some(&42));
assert_eq!(map.get(MyKey::First(false)), None);
assert_eq!(map.get(MyKey::Second), Some(&100));

other.retain(|k, v| matches!(k, MyKey::First(_)));

assert_eq!(other.len(), 2);
assert_eq!(other.get(MyKey::First(true)), Some(&42));
assert_eq!(other.get(MyKey::First(false)), Some(&-31));
assert_eq!(other.get(MyKey::Second), None);
source

pub fn clear(&mut self)

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    One,
    Two,
}

let mut map = Map::new();
map.insert(MyKey::One, "a");
map.clear();
assert!(map.is_empty());
source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut map = Map::new();
assert!(map.is_empty());
map.insert(MyKey::First, 1);
assert!(!map.is_empty());

An empty key:

use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {}

let map = Map::<MyKey, u32>::new();
assert!(map.is_empty());
source

pub fn len(&self) -> usize

Gets the current length of a Map.

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut map: Map<MyKey, i32> = Map::new();
assert_eq!(map.len(), 0);

map.insert(MyKey::First, 42);
assert_eq!(map.len(), 1);

map.insert(MyKey::First, 42);
assert_eq!(map.len(), 1);

map.remove(MyKey::First);
assert_eq!(map.len(), 0);

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut map: Map<MyKey, i32> = Map::new();
assert_eq!(map.len(), 0);

map.insert(MyKey::First(true), 42);
assert_eq!(map.len(), 1);

map.insert(MyKey::First(false), 42);
assert_eq!(map.len(), 2);

map.remove(MyKey::First(true));
assert_eq!(map.len(), 1);
source

pub fn entry(&mut self, key: K) -> Entry<'_, K::MapStorage<V>, K, V>

Gets the given key’s corresponding Entry in the Map for in-place manipulation.

§Examples
use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    Even,
    Odd,
}

let mut map: Map<MyKey, u32> = Map::new();

for n in [3, 45, 3, 23, 2, 10, 59, 11, 51, 70] {
    map
        .entry(if n % 2 == 0 { MyKey::Even } else { MyKey::Odd })
        .and_modify(|x| *x += 1)
        .or_insert(1);
}

assert_eq!(map.get(MyKey::Even), Some(&3));
assert_eq!(map.get(MyKey::Odd), Some(&7));

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Clone, Copy, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut map: Map<MyKey, Vec<i32>> = Map::new();

map.entry(MyKey::First(true)).or_default().push(1);
map.entry(MyKey::Second).or_insert_with(|| vec![2; 8]).truncate(4);

assert_eq!(map.get(MyKey::First(true)), Some(&vec![1]));
assert_eq!(map.get(MyKey::Second), Some(&vec![2; 4]));

Trait Implementations§

source§

impl<K, V> Clone for Map<K, V>
where K: Key, K::MapStorage<V>: Clone,

Clone implementation for a Map.

§Examples

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First(true), 1);
let mut b = a.clone();
b.insert(MyKey::Second, 2);

assert_ne!(a, b);

assert_eq!(a.get(MyKey::First(true)), Some(&1));
assert_eq!(a.get(MyKey::Second), None);

assert_eq!(b.get(MyKey::First(true)), Some(&1));
assert_eq!(b.get(MyKey::Second), Some(&2));
source§

fn clone(&self) -> Map<K, V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K, V> Debug for Map<K, V>
where K: Key + Debug, V: Debug,

The Debug implementation for a Map.

§Examples

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First, 42);

assert_eq!("{First: 42}", format!("{:?}", a));
source§

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

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

impl<K, V> Default for Map<K, V>
where K: Key,

The Default implementation for a Map produces an empty map.

§Examples

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let a = Map::<MyKey, u32>::default();
let b = Map::<MyKey, u32>::new();

assert_eq!(a, b);
source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, K, V> Deserialize<'de> for Map<K, V>
where K: Key + Deserialize<'de>, V: Deserialize<'de>,

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<K, V> FromIterator<(K, V)> for Map<K, V>
where K: Key,

A simple FromIterator implementation for Map.

§Example

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let v = vec![(MyKey::First, 1), (MyKey::Second, 2), (MyKey::First, 3)];
let m: Map<_, u8> = v.into_iter().collect();

let mut n = Map::new();
n.insert(MyKey::Second, 2);
n.insert(MyKey::First, 3);

assert_eq!(m, n);
source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
source§

impl<K, V> Hash for Map<K, V>
where K: Key, K::MapStorage<V>: Hash,

Hash implementation for a Set.

§Examples

use std::collections::HashSet;

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Hash, Key)]
enum MyKey {
    First,
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First, 1);

let mut set = HashSet::new();
set.insert(a);

Using a composite key:

use std::collections::HashSet;

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Hash, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First(true), 1);

// TODO: support this
// let mut set = HashSet::new();
// set.insert(a);
source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, K, V> IntoIterator for &'a Map<K, V>
where K: Key,

§

type Item = (K, &'a V)

The type of the elements being iterated over.
§

type IntoIter = <<K as Key>::MapStorage<V> as MapStorage<K, V>>::Iter<'a>

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<'a, K, V> IntoIterator for &'a mut Map<K, V>
where K: Key,

IntoIterator implementation which uses Map::iter_mut. See its documentation for more.

§

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

The type of the elements being iterated over.
§

type IntoIter = <<K as Key>::MapStorage<V> as MapStorage<K, V>>::IterMut<'a>

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, V> IntoIterator for Map<K, V>
where K: Key,

Produce an owning iterator visiting all key-value pairs of the Map in an arbitrary order. The iterator element type is (K, V).

§Examples

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
enum MyKey {
    First,
    Second,
    Third,
}

let mut map = Map::new();
map.insert(MyKey::First, 1);
map.insert(MyKey::Third, 3);

let mut it = map.into_iter();
assert_eq!(it.next(), Some((MyKey::First, 1)));
assert_eq!(it.next(), Some((MyKey::Third, 3)));
assert_eq!(it.next(), None);

let mut it = map.into_iter().rev();
assert_eq!(it.next(), Some((MyKey::Third, 3)));
assert_eq!(it.next(), Some((MyKey::First, 1)));
assert_eq!(it.next(), None);

Into iterator with a composite key:

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Key)]
enum MyKey {
    First(bool),
    Second,
    Third,
}

let mut map = Map::<_, u32>::new();
map.insert(MyKey::First(false), 1);
map.insert(MyKey::Third, 3);

let mut it = map.into_iter();
assert_eq!(it.next(), Some((MyKey::First(false), 1)));
assert_eq!(it.next(), Some((MyKey::Third, 3)));
assert_eq!(it.next(), None);

let mut it = map.into_iter().rev();
assert_eq!(it.next(), Some((MyKey::Third, 3)));
assert_eq!(it.next(), Some((MyKey::First(false), 1)));
assert_eq!(it.next(), None);
§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = <<K as Key>::MapStorage<V> as MapStorage<K, V>>::IntoIter

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, V> Ord for Map<K, V>
where K: Key, K::MapStorage<V>: Ord,

Ord implementation for a Map.

For more details on ordering, see the Key documentation.

§Examples

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Hash, Key)]
enum MyKey {
    First,
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First, 1);

let mut b = Map::new();
b.insert(MyKey::Second, 1);

let mut list = vec![b, a];
list.sort();

assert_eq!(list, [a, b]);

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Hash, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First(true), 1);

let mut b = Map::new();
b.insert(MyKey::Second, 1);

// TODO: support this
// let mut list = vec![a, b];
// list.sort();
source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
source§

fn max(self, other: Self) -> Self

Compares and returns the maximum of two values. Read more
source§

fn min(self, other: Self) -> Self

Compares and returns the minimum of two values. Read more
source§

fn clamp(self, min: Self, max: Self) -> Self

Restrict a value to a certain interval. Read more
source§

impl<K, V> PartialEq for Map<K, V>
where K: Key, K::MapStorage<V>: PartialEq,

PartialEq implementation for a Map.

§Examples

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First, 42);
// Note: `a` is Copy since it's using a simple key.
let mut b = a;

assert_eq!(a, b);

b.insert(MyKey::Second, 42);
assert_ne!(a, b);

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First(true), 42);
let mut b = a.clone();

assert_eq!(a, b);

b.insert(MyKey::Second, 42);
assert_ne!(a, b);
source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K, V> PartialOrd for Map<K, V>
where K: Key, K::MapStorage<V>: PartialOrd,

PartialOrd implementation for a Map.

For more details on ordering, see the Key documentation.

§Examples

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Hash, Key)]
enum MyKey {
    First,
    Second,
    Third,
}

let mut a = Map::new();
a.insert(MyKey::First, 1);

let mut b = Map::new();
b.insert(MyKey::Third, 1);

assert!(a < b);

let mut empty = Map::new();
assert!(empty < a);
assert!(empty < b);

Using a composite key:

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Hash, Key)]
enum MyKey {
    First(bool),
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First(true), 1);

let mut b = Map::new();
b.insert(MyKey::Second, 1);

// TODO: support this
// assert!(a < b);
source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
source§

fn lt(&self, other: &Self) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
source§

fn le(&self, other: &Self) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
source§

fn gt(&self, other: &Self) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
source§

fn ge(&self, other: &Self) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<K, V> Serialize for Map<K, V>
where K: Key + Serialize, V: Serialize,

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<K, V> Copy for Map<K, V>
where K: Key, K::MapStorage<V>: Copy,

The Copy implementation for a Map depends on its Key. If the derived key only consists of unit variants the corresponding Map will be Copy as well.

§Examples

use fixed_map::{Key, Map};

#[derive(Debug, Clone, Copy, Key)]
enum MyKey {
    First,
    Second,
}

let mut a = Map::new();
a.insert(MyKey::First, 1);
let mut b = a;
b.insert(MyKey::Second, 2);

assert_ne!(a, b);

assert_eq!(a.get(MyKey::First), Some(&1));
assert_eq!(a.get(MyKey::Second), None);

assert_eq!(b.get(MyKey::First), Some(&1));
assert_eq!(b.get(MyKey::Second), Some(&2));
source§

impl<K, V> Eq for Map<K, V>
where K: Key, K::MapStorage<V>: Eq,

Auto Trait Implementations§

§

impl<K, V> Freeze for Map<K, V>
where <K as Key>::MapStorage<V>: Freeze,

§

impl<K, V> RefUnwindSafe for Map<K, V>
where <K as Key>::MapStorage<V>: RefUnwindSafe,

§

impl<K, V> Send for Map<K, V>
where <K as Key>::MapStorage<V>: Send,

§

impl<K, V> Sync for Map<K, V>
where <K as Key>::MapStorage<V>: Sync,

§

impl<K, V> Unpin for Map<K, V>
where <K as Key>::MapStorage<V>: Unpin,

§

impl<K, V> UnwindSafe for Map<K, V>
where <K as Key>::MapStorage<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

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

Checks if this value is equivalent to the given key. 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

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

§

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>,

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,