Struct Map

pub struct Map<K, V> { /* private fields */ }

Represents a TOML key/value type.

Implementations

impl Map<String, Value>

fn try_from<T>(value: T) -> Result<Self, Error>
where
    T: Serialize,

Convert a T into toml::Table.

This conversion can fail if T's implementation of Serialize decides to fail, or if T contains a map with non-string keys.

fn try_into<'de, T>(self) -> Result<T, Error>
where
    T: Deserialize<'de>,

Interpret a toml::Table as an instance of type T.

This conversion can fail if the structure of the Table does not match the structure expected by T, for example if T is a bool which can't be mapped to a Table. It can also fail if the structure is correct but T's implementation of Deserialize decides that something is wrong with the data, for example required struct fields are missing from the TOML map or some number is too big to fit in the expected primitive type.

impl<'i> Map<Spanned<Cow<'i, str>>, Spanned<DeValue<'i>>>

fn parse(input: &'i str) -> Result<Spanned<Self>, Error>

Parse a TOML document

fn parse_recoverable(input: &'i str) -> (Spanned<Self>, Vec<Error>)

Parse a TOML document, with best effort recovery on error

fn make_owned(&mut self)

Ensure no data is borrowed

impl<K, V> Map<K, V> where K: Ord + Hash,

fn new() -> Self

Makes a new empty Map.

fn with_capacity(capacity: usize) -> Self

Makes a new empty Map with the given initial capacity.

fn clear(&mut self)

Clears the map, removing all values.

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

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map's key type, but the ordering on the borrowed form must match the ordering on the key type.

fn contains_key<Q>(&self, key: &Q) -> bool
where
    K: Borrow<Q>,
    Q: Ord + Eq + Hash + ?Sized,

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

The key may be any borrowed form of the map's key type, but the ordering on the borrowed form must match the ordering on the key type.

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

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

The key may be any borrowed form of the map's key type, but the ordering on the borrowed form must match the ordering on the key type.

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

Returns the key-value pair matching the given key.

The key may be any borrowed form of the map's key type, but the ordering on the borrowed form must match the ordering on the key type.

fn insert(&mut self, k: K, v: 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. The key is not updated, though; this matters for types that can be == without being identical.

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

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

The key may be any borrowed form of the map's key type, but the ordering on the borrowed form must match the ordering on the key type.

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

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

fn retain<F>(&mut self, keep: F)
where
    K: AsRef<str>,
    F: FnMut(&str, &mut V) -> bool,

Retains only the elements specified by the keep predicate.

In other words, remove all pairs (k, v) for which keep(&k, &mut v) returns false.

The elements are visited in iteration order.

fn entry<S>(&mut self, key: S) -> Entry<'_, K, V>
where
    S: Into<K>,

Gets the given key's corresponding entry in the map for in-place manipulation.

fn len(&self) -> usize

Returns the number of elements in the map.

fn is_empty(&self) -> bool

Returns true if the map contains no elements.

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

Gets an iterator over the entries of the map.

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

Gets a mutable iterator over the entries of the map.

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

Gets an iterator over the keys of the map.

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

Gets an iterator over the values of the map.

Trait Implementations

impl<K, V> Default for Map<K, V> where K: Ord + Hash,

fn default() -> Self

impl<K, V> IntoIterator for Map<K, V>

type Item = (K, V);
type IntoIter = IntoIter<K, V>;
fn into_iter(self) -> Self::IntoIter

impl<K, V, Q> Index<&Q> for Map<K, V> where K: Borrow<Q> + Ord, Q: Ord + Eq + Hash + ?Sized,

type Output = V;
fn index(&self, index: &Q) -> &V

impl<K, V, Q> IndexMut<&Q> for Map<K, V> where K: Borrow<Q> + Ord, Q: Ord + Eq + Hash + ?Sized,

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

impl<K: Clone, V: Clone> Clone for Map<K, V>

fn clone(&self) -> Self

impl<K: Debug, V: Debug> Debug for Map<K, V>

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

impl<K: Eq + Hash, V: PartialEq> PartialEq for Map<K, V>

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

impl<K: Ord + Hash, V> Extend<(K, V)> for Map<K, V>

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

impl<K: Ord + Hash, V> FromIterator<(K, V)> for Map<K, V>

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

Auto Trait Implementations

impl<K, V> Freeze for Map<K, V> where BTreeMap<K, V>: Freeze,

impl<K, V> RefUnwindSafe for Map<K, V> where BTreeMap<K, V>: RefUnwindSafe,

impl<K, V> Send for Map<K, V> where BTreeMap<K, V>: Send,

impl<K, V> Sync for Map<K, V> where BTreeMap<K, V>: Sync,

impl<K, V> Unpin for Map<K, V> where BTreeMap<K, V>: Unpin,

impl<K, V> UnsafeUnpin for Map<K, V> where BTreeMap<K, V>: UnsafeUnpin,

impl<K, V> UnwindSafe for Map<K, V> where BTreeMap<K, V>: UnwindSafe,

Blanket Implementations

impl<T> Any for Map<K, V> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Map<K, V> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Map<K, V> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Map<K, V> where T: Clone,

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

impl<T> DeserializeOwned for Map<K, V> where T: for<'de> Deserialize<'de>,

impl<T> From<T> for Map<K, V>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Map<K, V> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> ToString for Map<K, V> where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T, U> Into<U> for Map<K, V> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Map<K, V> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Map<K, V> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>