Skip to main content

Map

Struct Map 

Source
pub struct Map { /* private fields */ }
Available on crate feature tree only.
Expand description

The members of an object of a tree, in the order in which they were written: a member that is added goes at the end, one that is given another value keeps its place, and one that is taken out leaves the others in theirs.

It is a list. An object of more than 256 members also keeps an index: the position of each member under the hash of its name, in the order of the hashes, so that a member is found by its name in a time that grows as log n, and no name is copied. Whatever builds an object of n members with insert, finds each of them, reads one from JSON or compares two takes a time that grows as n log n. Moving or taking out a member, which moves those after it, takes a time that grows as n.

Implementations§

Source§

impl Map

Source

pub fn new() -> Self

An object without members.

Source

pub fn with_capacity(capacity: usize) -> Self

An object without members, with room for capacity of them.

Source

pub fn len(&self) -> usize

How many members it has.

Source

pub fn is_empty(&self) -> bool

Whether it has none.

Source

pub fn clear(&mut self)

Take every member out.

Source

pub fn get(&self, name: &str) -> Option<&Value>

The member of this name.

Source

pub fn get_mut(&mut self, name: &str) -> Option<&mut Value>

The member of this name, to change.

Source

pub fn get_key_value(&self, name: &str) -> Option<(&String, &Value)>

The member of this name, with its name as the object has it.

Source

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

Whether it has a member of this name.

Source

pub fn insert(&mut self, name: String, value: Value) -> Option<Value>

Give the member name the value value: at its place when the object has it, and at the end otherwise. The value that it had, if any.

Source

pub fn shift_insert( &mut self, position: usize, name: String, value: Value, ) -> Option<Value>

Give the member name the value value at position, or at the end for a position past it: the member moves there when the object has it. The value that it had, if any.

Source

pub fn shift_remove(&mut self, name: &str) -> Option<Value>

Take the member name out, and leave the others in their order.

Source

pub fn remove(&mut self, name: &str) -> Option<Value>

Take the member name out, and leave the others in their order: as shift_remove, which keeps the order of the members, and not as the swap_remove of an IndexMap.

Source

pub fn entry(&mut self, name: impl Into<String>) -> Entry<'_>

The member name, to give it a value when it has none.

Source

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

Keep the members for which keep says so.

Source

pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = (&String, &Value)> + ExactSizeIterator

The members, in their order.

Source

pub fn iter_mut( &mut self, ) -> impl DoubleEndedIterator<Item = (&String, &mut Value)> + ExactSizeIterator

The members, in their order, to change their values.

Source

pub fn keys( &self, ) -> impl DoubleEndedIterator<Item = &String> + ExactSizeIterator

The names of the members, in their order.

Source

pub fn values( &self, ) -> impl DoubleEndedIterator<Item = &Value> + ExactSizeIterator

The values of the members, in their order.

Source

pub fn values_mut( &mut self, ) -> impl DoubleEndedIterator<Item = &mut Value> + ExactSizeIterator

The values of the members, in their order, to change them.

Trait Implementations§

Source§

impl Clone for Map

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 Map

Source§

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

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

impl Default for Map

Source§

fn default() -> Self

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

impl Eq for Map

Source§

impl Extend<(String, Value)> for Map

Source§

fn extend<I: IntoIterator<Item = (String, Value)>>(&mut self, members: I)

The members after those of the object, as insert adds them one after the other.

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<Map> for Value

Source§

fn from(members: Map) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(String, Value)> for Map

Source§

fn from_iter<I: IntoIterator<Item = (String, Value)>>(members: I) -> Self

The members in the order of the iterator; a name that comes again gives its member the last value, at the place of the first.

Source§

impl Index<&str> for Map

Source§

fn index(&self, name: &str) -> &Value

§Panics

When the object has no member of this name.

Source§

type Output = Value

The returned type after indexing.
Source§

impl IndexMut<&str> for Map

Source§

fn index_mut(&mut self, name: &str) -> &mut Value

§Panics

When the object has no member of this name.

Source§

impl<'m> IntoIterator for &'m Map

Source§

type Item = (&'m String, &'m Value)

The type of the elements being iterated over.
Source§

type IntoIter = Map<Iter<'m, (String, Value)>, fn(&'m (String, Value)) -> (&'m String, &'m Value)>

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<'m> IntoIterator for &'m mut Map

Source§

type Item = (&'m String, &'m mut Value)

The type of the elements being iterated over.
Source§

type IntoIter = Map<IterMut<'m, (String, Value)>, fn(&'m mut (String, Value)) -> (&'m String, &'m mut Value)>

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 IntoIterator for Map

Source§

type Item = (String, Value)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<(String, Value)>

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 PartialEq for Map

Source§

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

Two objects are equal when they have the same members, whatever their order.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Freeze for Map

§

impl RefUnwindSafe for Map

§

impl Send for Map

§

impl Sync for Map

§

impl Unpin for Map

§

impl UnsafeUnpin for Map

§

impl UnwindSafe for Map

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