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
impl TextMap
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
True when key has a value.
Sourcepub fn insert<K: AsRef<str> + Into<Box<str>>>(
&mut self,
key: K,
value: impl Into<Box<str>>,
) -> Option<Box<str>>
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.
Sourcepub fn retain(&mut self, keep: impl FnMut(&str, &str) -> bool)
pub fn retain(&mut self, keep: impl FnMut(&str, &str) -> bool)
Keeps only the entries for which keep returns true.
Sourcepub fn get_or_insert_with<K: AsRef<str> + Into<Box<str>>, T: Into<Box<str>>>(
&mut self,
key: K,
make: impl FnOnce() -> T,
) -> &str
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.
Sourcepub fn values(&self) -> TextValues<'_>
pub fn values(&self) -> TextValues<'_>
The values, in key order.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TextMap
impl<'de> Deserialize<'de> for TextMap
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<TextMap, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<TextMap, D::Error>
From an object of strings; for a repeated key the last value wins.
impl Eq for TextMap
Source§impl<K: Into<Box<str>>, T: Into<Box<str>>> Extend<(K, T)> for TextMap
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)
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)
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)
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<'a> IntoIterator for &'a TextMap
impl<'a> IntoIterator for &'a TextMap
Source§impl IntoIterator for TextMap
impl IntoIterator for TextMap
Source§impl Ord for TextMap
impl Ord for TextMap
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for TextMap
impl PartialOrd for TextMap
impl StructuralPartialEq for TextMap
Auto Trait Implementations§
impl Forget for TextMap
impl Freeze for TextMap
impl Move for TextMap
impl RefUnwindSafe for TextMap
impl Send for TextMap
impl Sync for TextMap
impl Unpin for TextMap
impl UnsafeUnpin for TextMap
impl UnwindSafe for TextMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more