Skip to main content

SmallMap

Struct SmallMap 

Source
pub struct SmallMap<V> { /* private fields */ }
Expand description

A map from text keys to V. See the module docs.

Implementations§

Source§

impl<V> SmallMap<V>

Source

pub fn new() -> SmallMap<V>

An empty map (allocates nothing).

Source

pub fn len(&self) -> usize

The number of entries.

Source

pub fn is_empty(&self) -> bool

True when the map has no entries.

Source

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

The value for key.

Source

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

The value for key, mutable.

Source

pub fn get_key_value(&self, key: &str) -> Option<(&str, &V)>

The stored key and the value for key.

Source

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

True when key has a value.

Source

pub fn insert<K: AsRef<str> + Into<Box<str>>>( &mut self, key: K, value: V, ) -> Option<V>

Sets the value for key and returns the one it replaces.

Source

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

Removes key and returns its value.

Source

pub fn clear(&mut self)

Removes every entry (and frees the storage).

Source

pub fn retain(&mut self, keep: impl FnMut(&str, &mut V) -> bool)

Keeps only the entries for which keep returns true.

Source

pub fn get_or_insert_with<K: AsRef<str> + Into<Box<str>>>( &mut self, key: K, make: impl FnOnce() -> V, ) -> &mut V

The value for key, inserting make() first when there is none (what entry(key).or_insert_with(make) does on a BTreeMap). The key is only converted when it is inserted.

Source

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

The entries as (&str, &V), in key order.

Source

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

The entries as (&str, &mut V), in key order.

Source

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

The keys, in order.

Source

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

The values, in key order.

Source

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

The values, mutable, in key order.

Trait Implementations§

Source§

impl<V: Clone> Clone for SmallMap<V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<V: Debug> Debug for SmallMap<V>

Source§

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

Prints like a BTreeMap: {"k": v, ...}.

Source§

impl<V> Default for SmallMap<V>

Source§

fn default() -> SmallMap<V>

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

impl<'de, V: Deserialize<'de>> Deserialize<'de> for SmallMap<V>

Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<SmallMap<V>, D::Error>

From an object; for a repeated key the last value wins, as serde_json does into a BTreeMap.

Source§

impl<V: Eq> Eq for SmallMap<V>

Source§

impl<K: Into<Box<str>>, V> Extend<(K, V)> for SmallMap<V>

Source§

fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)

A new value replaces an old one for the same key; of repeated new keys the last wins. A slice merges the new entries in one pass; a tree inserts them one by one.

Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<V: Clone> From<&SmallMap<V>> for SmallMap<V>

Source§

fn from(m: &SmallMap<V>) -> SmallMap<V>

A copy. Codes::from(unit.codes()) takes an owned copy of a unit’s codes, whatever codes() returns.

Source§

impl<V> From<BTreeMap<String, V>> for SmallMap<V>

Source§

fn from(m: BTreeMap<String, V>) -> SmallMap<V>

Already in order: no sort.

Source§

impl<V> From<SmallMap<V>> for BTreeMap<String, V>

Source§

fn from(m: SmallMap<V>) -> BTreeMap<String, V>

Converts to this type from the input type.
Source§

impl<K: Into<Box<str>>, V, const N: usize> From<[(K, V); N]> for SmallMap<V>

Source§

fn from(a: [(K, V); N]) -> SmallMap<V>

Converts to this type from the input type.
Source§

impl<K: Into<Box<str>>, V> FromIterator<(K, V)> for SmallMap<V>

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> SmallMap<V>

Sorts once; for a repeated key the last value wins, as when collecting into a BTreeMap.

Source§

impl<V: Hash> Hash for SmallMap<V>

Source§

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

The length, then every entry in order: equal maps hash the same in either representation.

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<V, Q: AsRef<str> + ?Sized> Index<&Q> for SmallMap<V>

Source§

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

The value for key. Panics when there is none, as a BTreeMap does.

Source§

type Output = V

The returned type after indexing.
Source§

impl<'a, V> IntoIterator for &'a SmallMap<V>

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, V>

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

fn into_iter(self) -> Iter<'a, V> ⓘ

Creates an iterator from a value. Read more
Source§

impl<'a, V> IntoIterator for &'a mut SmallMap<V>

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, V>

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

fn into_iter(self) -> IterMut<'a, V> ⓘ

Creates an iterator from a value. Read more
Source§

impl<V> IntoIterator for SmallMap<V>

Source§

type Item = (Box<str>, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<V>

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

fn into_iter(self) -> IntoIter<V> ⓘ

Creates an iterator from a value. Read more
Source§

impl<V: Ord> Ord for SmallMap<V>

Source§

fn cmp(&self, other: &SmallMap<V>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<V: PartialEq> PartialEq for SmallMap<V>

Source§

fn eq(&self, other: &SmallMap<V>) -> bool

Same entries, whichever representation each side has.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<V: PartialOrd> PartialOrd for SmallMap<V>

Source§

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

Entry by entry, as a BTreeMap compares.

1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<V: Serialize> Serialize for SmallMap<V>

Source§

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

A JSON object, keys in order: the bytes a BTreeMap<String, V> writes.

Auto Trait Implementations§

§

impl<V> Forget for SmallMap<V>

§

impl<V> Freeze for SmallMap<V>
where Repr<V>: Freeze,

§

impl<V> Move for SmallMap<V>

§

impl<V> RefUnwindSafe for SmallMap<V>
where Repr<V>: RefUnwindSafe,

§

impl<V> Send for SmallMap<V>
where Repr<V>: Send,

§

impl<V> Sync for SmallMap<V>
where Repr<V>: Sync,

§

impl<V> Unpin for SmallMap<V>
where Repr<V>: Unpin,

§

impl<V> UnsafeUnpin for SmallMap<V>
where Repr<V>: UnsafeUnpin,

§

impl<V> UnwindSafe for SmallMap<V>
where Repr<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.