Skip to main content

MapData

Struct MapData 

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

The contents of a map. Holds pairs of keys and values in insertion order, with an index for looking up keys (key → where the pair is stored).

  • Lookup, update, insertion and removal take time proportional to the size of the key (not a linear search). Keys are compared and hashed as values, without converting them to strings.
  • Removal only empties the slot of the pair, without shifting the pairs after it. When the holes exceed the number of pairs, they are compacted at once (amortized constant time per removal). MapData::entries goes through the pairs in insertion order, skipping holes.
  • Cloning only shares the Arc (the first update after cloning copies the contents). Reading a huge map does not mean copying the whole thing every time. A clone is independent of the original (value semantics).
  • The index is not saved. It is rebuilt on restore (From<Vec<_>>, Deserialize).
  • Keeps the total size of the pairs (the estimate of Value::approx_bytes) incrementally, so checking value sizes is not proportional to the size of the map. When a value inside nesting is updated, the outer side reports it with adjust_bytes (within the crate).
  • == does not compare insertion order (equal if they have the same values for the same keys).

Implementations§

Source§

impl MapData

Source

pub fn new() -> Self

An empty map.

Source

pub fn from_pairs(pairs: Vec<(Value, Value)>) -> Self

Makes one from a sequence of pairs. If a key repeats, the later value updates it (the position stays the first one).

Source

pub fn entries(&self) -> MapEntries<'_> ⓘ

Goes through the pairs in insertion order.

Source

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

Goes through the pairs in insertion order (same as MapData::entries).

Source

pub fn len(&self) -> usize

The number of pairs.

Source

pub fn is_empty(&self) -> bool

Whether there are no pairs.

Source

pub fn into_entries(self) -> Vec<(Value, Value)>

Takes the pairs out (in insertion order). Does not copy the pairs if not shared.

Source

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

Whether the key exists.

Source

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

The value of the key.

Trait Implementations§

Source§

impl Clone for MapData

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 MapData

Shows only the sequence of pairs ([(key, value), …]), without the index or holes (so the output is stable).

Source§

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

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

impl Default for MapData

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for MapData

Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Vec<(Value, Value)>> for MapData

Source§

fn from(pairs: Vec<(Value, Value)>) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a MapData

Source§

type Item = &'a (Value, Value)

The type of the elements being iterated over.
Source§

type IntoIter = MapEntries<'a>

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 MapData

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 Serialize for MapData

Source§

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

Serialize this value into the given Serde serializer. Read more

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.