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.
Implementations§
Source§impl MapKey
impl MapKey
Sourcepub fn from_value(value: &Value) -> Result<MapKey, InvalidKey>
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.
Trait Implementations§
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.
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.
impl Eq for MapKey
Source§impl Ord for MapKey
impl Ord for MapKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for MapKey
impl PartialOrd for MapKey
impl StructuralPartialEq for MapKey
Auto Trait Implementations§
impl Freeze for MapKey
impl RefUnwindSafe for MapKey
impl Send for MapKey
impl Sync for MapKey
impl Unpin for MapKey
impl UnsafeUnpin for MapKey
impl UnwindSafe for MapKey
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.