Skip to main content

MapKey

Enum MapKey 

Source
pub enum MapKey {
    Unit,
    Bool(bool),
    Int(i64),
    Duration(i64),
    Str(String),
    EnumCase(String, String, Vec<MapKey>),
    Struct(String, Vec<(String, MapKey)>, bool),
    Array(Vec<MapKey>),
    Set(BTreeSet<MapKey>),
    Map(BTreeMap<MapKey, MapKey>),
    Range {
        start: i64,
        end: i64,
        inclusive_end: bool,
    },
}
Expand description

A value usable as a Map key or Set element.

ADR 0001 draws the line at mutability, not at primitives: “mutable handles and structs containing them are not valid map keys.” A key’s equality must not change while a collection holds it, so this is recursive rather than a flat list of primitive shapes — a Struct, an Array, or an enum case with a payload qualifies exactly when everything nested inside it does. Map and Set qualify too: both are immutable handles, so nesting one as a key changes nothing about the rule, only how deep the check goes. A Range qualifies for the same reason: it is an immutable value with a stable eq_value, ordered consistently by its (start, end, inclusive_end) fields. Float is rejected for an unrelated reason: NaN is not equal to itself, which breaks the total order every key needs.

Variants§

§

Unit

§

Bool(bool)

§

Int(i64)

§

Duration(i64)

§

Str(String)

§

EnumCase(String, String, Vec<MapKey>)

An enum case, keyed by (type, case), with every payload value converted the same way.

§

Struct(String, Vec<(String, MapKey)>, bool)

A struct, keyed by type name, with every field converted the same way, in declaration order, and whether its type is opaque — a key is rendered back as a value for keys() and for Display, and a value of an opaque type shows only its name wherever it is read from.

§

Array(Vec<MapKey>)

An array, with every element converted the same way. An array is fixed-length and immutable, so its equality cannot change.

§

Set(BTreeSet<MapKey>)

A Set. Its elements are already MapKeys by construction, so nesting one never fails.

§

Map(BTreeMap<MapKey, MapKey>)

A Map. Its keys are already MapKeys by construction; only its values need converting, and the first one that cannot be is why nesting a Map as a key can still fail.

§

Range

A range. Immutable with a stable eq_value, so it qualifies under the same rule as every other key: its equality cannot change while a collection holds it. Ordered by (start, end, inclusive_end), which is a total order because every field is.

Fields

§start: i64
§end: i64
§inclusive_end: bool

Implementations§

Source§

impl MapKey

Source

pub fn from_value(value: &Value) -> Result<MapKey, InvalidKey>

Converts value to a map key or set element, or reports the specific part that cannot be one, with the path to reach it.

Source

pub fn to_value(&self) -> Value

Renders this key back as an ordinary value, for keys(), Set iteration, and toArray().

Trait Implementations§

Source§

impl Clone for MapKey

Source§

fn clone(&self) -> MapKey

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 MapKey

Source§

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

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

impl Display for MapKey

A key displays exactly as the value it represents would, so a Map’s entries read the same way here as they would anywhere else in the language.

Source§

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

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

impl Eq for MapKey

Source§

impl Ord for MapKey

Source§

fn cmp(&self, other: &MapKey) -> 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§

impl PartialEq for MapKey

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for MapKey

Source§

fn partial_cmp(&self, other: &MapKey) -> 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 StructuralPartialEq for MapKey

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.