pub struct Map<K, V> { /* private fields */ }Expand description
An immutable, reference-counted map from K to V, passed across
languages as ffi.Map.
Cloning a Map is cheap: it shares the same entries.
§Examples
use tvm_ffi::{Map, String};
let map: Map<String, i64> = [(String::from("a"), 1), (String::from("b"), 2)]
.into_iter()
.collect();
assert_eq!(map.len(), 2);
assert_eq!(map.get("b")?, Some(2));
assert_eq!(map.get("c")?, None);Implementations§
Source§impl<K, V> Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<K, V> Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Sourcepub fn contains_key(&self, key: impl IntoArg<K>) -> Result<bool>
pub fn contains_key(&self, key: impl IntoArg<K>) -> Result<bool>
Sourcepub fn get(&self, key: impl IntoArg<K>) -> Result<Option<V>>
pub fn get(&self, key: impl IntoArg<K>) -> Result<Option<V>>
Looks up key, returning Ok(None) if it is absent.
§Errors
Returns an error if the runtime cannot look key up, such as when it
is not hashable, or if the value is not a V.
The result for a key of another type than the map’s keys is
unspecified: it currently reads as absent, since a lookup hashes the key
instead of reading a stored one. Debug builds assert against it.
A &str key builds a temporary String for the runtime lookup. Code
generic over K that passes a &K adds the bound
for<'a> &'a K: IntoArg<K>.
Source§impl<K, V> Map<K, V>
impl<K, V> Map<K, V>
Sourcepub fn upcast<KU: TypeSubsumes<K>, VU: TypeSubsumes<V>>(self) -> Map<KU, VU>
pub fn upcast<KU: TypeSubsumes<K>, VU: TypeSubsumes<V>>(self) -> Map<KU, VU>
View this map as a Map<KU, VU> without a copy, as C++
Map<KU, VU>(const Map<K, V>&) does for bases KU and VU.
It is a method, not From, for the reasons on Array::upcast.
Sourcepub fn upcast_ref<KU: TypeSubsumes<K>, VU: TypeSubsumes<V>>(
&self,
) -> &Map<KU, VU>
pub fn upcast_ref<KU: TypeSubsumes<K>, VU: TypeSubsumes<V>>( &self, ) -> &Map<KU, VU>
Borrow this map as a Map<KU, VU>, as upcast does.
Trait Implementations§
Source§impl<K, V> AnyCompatible for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<K, V> AnyCompatible for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Source§unsafe fn is_undefined(field: *const Self) -> bool
unsafe fn is_undefined(field: *const Self) -> bool
field, which holds a value of this type or all-zero bytes,
holds all-zero bytes that are no value of this type, as a null object
reference, a string of type index None or a zero device type: a field
that a creator left undefined for reflection to set. An undefined field
is no value; a nullable reference is Option<T>, whose None is a
defined value. Read moreSource§fn type_str() -> String
fn type_str() -> String
int,
ffi.String or Array<int>.Source§fn type_schema() -> String
fn type_schema() -> String
Source§unsafe fn check_any_strict(data: &TVMFFIAny) -> bool
unsafe fn check_any_strict(data: &TVMFFIAny) -> bool
Source§unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)
unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)
Source§unsafe fn move_to_any(src: Self, data: &mut TVMFFIAny)
unsafe fn move_to_any(src: Self, data: &mut TVMFFIAny)
Source§unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self
unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self
Self out of a cell that holds one, retaining any object. Read moreSource§unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
Self out of an owning cell that holds one. Read moreSource§unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
data into a Self by the FFI rules, such as an integer into a
float; Err if it does not convert. Read moreSource§fn get_mismatch_type_info(data: &TVMFFIAny) -> String
fn get_mismatch_type_info(data: &TVMFFIAny) -> String
data in conversion errors; by
default its runtime type key.Source§impl<K, V> Debug for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<K, V> Debug for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Source§impl<K, V> Default for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<K, V> Default for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Source§impl<K: ContainerElement, V: ContainerElement> Display for Map<K, V>
Formats the map as its repr; see AnyView.
impl<K: ContainerElement, V: ContainerElement> Display for Map<K, V>
Formats the map as its repr; see AnyView.
Source§impl<K, V> DowncastRefFromAny for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<K, V> DowncastRefFromAny for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Source§unsafe fn downcast_ref_from_any(cell: &TVMFFIAny) -> Option<&Self>
unsafe fn downcast_ref_from_any(cell: &TVMFFIAny) -> Option<&Self>
Source§impl<K, V> From<&Map<K, V>> for Map<K, V>
A reference-count bump, as From<&T> for T of an object reference.
impl<K, V> From<&Map<K, V>> for Map<K, V>
A reference-count bump, as From<&T> for T of an object reference.
Source§impl<K: ContainerElement, V: ContainerElement, const N: usize> From<[(K, V); N]> for Map<K, V>
impl<K: ContainerElement, V: ContainerElement, const N: usize> From<[(K, V); N]> for Map<K, V>
Source§impl<K, V> From<Map<K, V>> for ObjectRefwhere
Map<K, V>: ObjectRefCore,
A map upcasts to the root ObjectRef.
impl<K, V> From<Map<K, V>> for ObjectRefwhere
Map<K, V>: ObjectRefCore,
A map upcasts to the root ObjectRef.
Source§impl<K, V> FromIterator<(K, V)> for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<K, V> FromIterator<(K, V)> for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Source§fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
For duplicate keys, a later pair overwrites an earlier one, as in
HashMap, so the resulting map may be smaller than the iterator.
Source§impl<'a, K, V, KU: TypeSubsumes<K> + 'a, VU: TypeSubsumes<V> + 'a> IntoArg<Map<KU, VU>> for &'a Map<K, V>
impl<'a, K, V, KU: TypeSubsumes<K> + 'a, VU: TypeSubsumes<V> + 'a> IntoArg<Map<KU, VU>> for &'a Map<K, V>
Source§impl<K, V, KU: TypeSubsumes<K>, VU: TypeSubsumes<V>> IntoArg<Map<KU, VU>> for Map<K, V>
impl<K, V, KU: TypeSubsumes<K>, VU: TypeSubsumes<V>> IntoArg<Map<KU, VU>> for Map<K, V>
Source§impl<K, V> IntoIterator for &Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<K, V> IntoIterator for &Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Source§impl<K: ContainerElement, V: ContainerElement> ObjectRefCore for Map<K, V>
impl<K: ContainerElement, V: ContainerElement> ObjectRefCore for Map<K, V>
Source§type ContainerType = MapObj
type ContainerType = MapObj
Source§unsafe fn from_data(data: ObjectArc<MapObj>) -> Self
unsafe fn from_data(data: ObjectArc<MapObj>) -> Self
Source§fn same_as<Other: ObjectRefCore>(&self, other: &Other) -> bool
fn same_as<Other: ObjectRefCore>(&self, other: &Other) -> bool
Source§fn type_key(&self) -> &'static str
fn type_key(&self) -> &'static str
"ffi.Array", as C++ ObjectRef::GetTypeKey.Source§fn is<T: AnyCompatible>(&self) -> bool
fn is<T: AnyCompatible>(&self) -> bool
T as is, such as a subtype or a container
whose elements are checked too, by the strict check of
downcast, without a reference count change.
See also crate::Any::is.Source§impl<'a, K: ContainerElement, V: ContainerElement> PackedCallArg for &'a Map<K, V>
impl<'a, K: ContainerElement, V: ContainerElement> PackedCallArg for &'a Map<K, V>
Source§impl<K: ContainerElement, V: ContainerElement> PackedCallArg for Map<K, V>
impl<K: ContainerElement, V: ContainerElement> PackedCallArg for Map<K, V>
Source§impl<'b, K, V> TryFrom<&'b Any> for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<'b, K, V> TryFrom<&'b Any> for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Source§impl<K, V> TryFrom<&ObjectRef> for Map<K, V>where
Map<K, V>: ObjectRefCore + DowncastRefFromObject,
impl<K, V> TryFrom<&ObjectRef> for Map<K, V>where
Map<K, V>: ObjectRefCore + DowncastRefFromObject,
Source§impl<K, V> TryFrom<Any> for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<K, V> TryFrom<Any> for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Source§impl<'a, K, V> TryFrom<AnyView<'a>> for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
impl<'a, K, V> TryFrom<AnyView<'a>> for Map<K, V>where
K: ContainerElement,
V: ContainerElement,
Source§impl<K, V> TryFrom<ObjectRef> for Map<K, V>where
Map<K, V>: ObjectRefCore,
The strict downcast from the root ObjectRef.
impl<K, V> TryFrom<ObjectRef> for Map<K, V>where
Map<K, V>: ObjectRefCore,
The strict downcast from the root ObjectRef.