Skip to main content

TextMap

Struct TextMap 

Source
pub struct TextMap(/* private fields */);
Expand description

A map from text to text (a unit’s hidden values, a context’s extras), stored as a SmallMap of Box<str>. It reads and writes &str: TextMap::get gives Option<&str> and iteration gives (&str, &str), so callers never see how the text is stored. JSON is an object of strings, as a BTreeMap<String, String>.

Implementations§

Source§

impl TextMap

Source

pub fn new() -> TextMap

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<&str>

The text 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: impl Into<Box<str>>, ) -> Option<Box<str>>

Sets the text for key and returns the text it replaces.

Source

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

Removes key and returns its text.

Source

pub fn clear(&mut self)

Removes every entry.

Source

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

Keeps only the entries for which keep returns true.

Source

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

The text for key, inserting make() first when there is none.

Source

pub fn iter(&self) -> TextIter<'_>

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

Source

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

The keys, in order.

Source

pub fn values(&self) -> TextValues<'_>

The values, in key order.

Trait Implementations§

Source§

impl Clone for TextMap

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 Debug for TextMap

Source§

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

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

Source§

impl Default for TextMap

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for TextMap

Source§

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

From an object of strings; for a repeated key the last value wins.

Source§

impl Eq for TextMap

Source§

impl<K: Into<Box<str>>, T: Into<Box<str>>> Extend<(K, T)> for TextMap

Source§

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

Adds the entries in one merge; a new value replaces an old one for the same key.

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 From<&TextMap> for TextMap

Source§

fn from(m: &TextMap) -> TextMap

A copy. TextMap::from(ctx.extra()) takes an owned copy, whatever extra() returns.

Source§

impl From<BTreeMap<String, String>> for TextMap

Source§

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

Already in order: no sort.

Source§

impl From<TextMap> for BTreeMap<String, String>

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn from(a: [(K, T); N]) -> TextMap

Converts to this type from the input type.
Source§

impl<K: Into<Box<str>>, T: Into<Box<str>>> FromIterator<(K, T)> for TextMap

Source§

fn from_iter<I: IntoIterator<Item = (K, T)>>(iter: I) -> TextMap

Sorts once; for a repeated key the last value wins.

Source§

impl Hash for TextMap

Source§

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

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

Source§

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

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

Source§

type Output = str

The returned type after indexing.
Source§

impl<'a> IntoIterator for &'a TextMap

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = Map<Iter<'a, Box<str>>, for<'x> fn((&'x str, &'x Box<str>)) -> (&'x str, &'x str)>

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

fn into_iter(self) -> TextIter<'a>

Creates an iterator from a value. Read more
Source§

impl IntoIterator for TextMap

Source§

type Item = (Box<str>, Box<str>)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Box<str>>

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

fn into_iter(self) -> TextIntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for TextMap

Source§

fn cmp(&self, other: &Self) -> 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 PartialEq for TextMap

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for TextMap

Source§

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

This method returns an ordering between self and other values if one exists. Read more
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 Serialize for TextMap

Source§

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

A JSON object of strings, keys in order.

Source§

impl StructuralPartialEq for TextMap

Auto Trait Implementations§

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.