pub struct ValueKey<'a>(/* private fields */);Expand description
A key for looking up elements in Value arrays and maps.
ValueKey is the parameter type of Value::get, Value::get_mut,
Value::remove, Value::contains, and the Index/IndexMut
implementations on Value. You rarely name it directly: it converts
from the same inputs that build a Value, so the same arguments work
for both.
Where building a Value from a reference would copy, ValueKey
borrows instead, so a lookup allocates nothing:
&str,&String,&[u8],&[u8; N]borrow the string data.&Valueborrows the value.&[Value],&Vec<Value>,&[Value; N],&Arrayborrow an array-valued key;&Mapand&BTreeMap<Value, Value>borrow a map-valued key, bypassing the full-Valueallocation a composite key would otherwise need.
Integers, floats, bool, SimpleValue, (), char, and owned inputs
(an owned Value, String, Vec<u8>, Array, Map, and so on) are
taken by value.
§Examples
use cbor_core::{Value, array, map};
let a = array![10, 20, 30];
assert_eq!(a[1].to_u32(), Ok(20));
let m = map! { "x" => 10, 2 => 20 };
assert_eq!(m["x"].to_u32(), Ok(10));
assert_eq!(m[2].to_u32(), Ok(20));
let k: [Value; _] = [1,2,3].map(Value::from);
let m = map! { k.clone() => "array as key" };
assert_eq!(m[&k].as_str(), Ok("array as key") );
let mut v = array![1, 2, 3];
v.remove(0);
assert_eq!(v.len(), Some(2));Trait Implementations§
Source§impl<'a> From<&'a ByteString<'a>> for ValueKey<'a>
impl<'a> From<&'a ByteString<'a>> for ValueKey<'a>
Source§fn from(value: &'a ByteString<'a>) -> Self
fn from(value: &'a ByteString<'a>) -> Self
Converts to this type from the input type.
Source§impl<'a> From<&'a TextString<'a>> for ValueKey<'a>
impl<'a> From<&'a TextString<'a>> for ValueKey<'a>
Source§fn from(value: &'a TextString<'a>) -> Self
fn from(value: &'a TextString<'a>) -> Self
Converts to this type from the input type.
Source§impl<'a> From<ByteString<'a>> for ValueKey<'a>
impl<'a> From<ByteString<'a>> for ValueKey<'a>
Source§fn from(value: ByteString<'a>) -> Self
fn from(value: ByteString<'a>) -> Self
Converts to this type from the input type.
Source§impl<'a, const LIMBS: usize> From<Int<LIMBS>> for ValueKey<'a>
Available on crate feature crypto-bigint only.
impl<'a, const LIMBS: usize> From<Int<LIMBS>> for ValueKey<'a>
Available on crate feature
crypto-bigint only.Source§impl<'a, const LIMBS: usize> From<NonZero<Int<LIMBS>>> for ValueKey<'a>
Available on crate feature crypto-bigint only.
impl<'a, const LIMBS: usize> From<NonZero<Int<LIMBS>>> for ValueKey<'a>
Available on crate feature
crypto-bigint only.Source§impl<'a, const LIMBS: usize> From<NonZero<Uint<LIMBS>>> for ValueKey<'a>
Available on crate feature crypto-bigint only.
impl<'a, const LIMBS: usize> From<NonZero<Uint<LIMBS>>> for ValueKey<'a>
Available on crate feature
crypto-bigint only.Source§impl<'a> From<SimpleValue> for ValueKey<'a>
impl<'a> From<SimpleValue> for ValueKey<'a>
Source§fn from(value: SimpleValue) -> Self
fn from(value: SimpleValue) -> Self
Converts to this type from the input type.
Source§impl<'a> From<TextString<'a>> for ValueKey<'a>
impl<'a> From<TextString<'a>> for ValueKey<'a>
Source§fn from(value: TextString<'a>) -> Self
fn from(value: TextString<'a>) -> Self
Converts to this type from the input type.
Source§impl<'a, const LIMBS: usize> From<Uint<LIMBS>> for ValueKey<'a>
Available on crate feature crypto-bigint only.
impl<'a, const LIMBS: usize> From<Uint<LIMBS>> for ValueKey<'a>
Available on crate feature
crypto-bigint only.Auto Trait Implementations§
impl<'a> Freeze for ValueKey<'a>
impl<'a> RefUnwindSafe for ValueKey<'a>
impl<'a> Send for ValueKey<'a>
impl<'a> Sync for ValueKey<'a>
impl<'a> Unpin for ValueKey<'a>
impl<'a> UnsafeUnpin for ValueKey<'a>
impl<'a> UnwindSafe for ValueKey<'a>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Casts the value.
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.