pub struct Map<K, V> { /* private fields */ }Expand description
Immutable, reference-counted map from K to V, sharing its underlying
MapObj with C++. Cloning is cheap (it bumps the refcount).
Implementations§
Source§impl<K, V> Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
impl<K, V> Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of entries in the map by reading the MapObj header
directly (no FFI call), like Array::len.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true if key is present in the map.
Panics if the lookup fails in the C++ runtime (e.g. key is not
hashable); use Map::get when such failures must be recovered from.
Passing a key whose type does not match the map’s key type is
undefined (currently reads as false; see Map::get); debug builds
assert against it.
Sourcepub fn get(&self, key: &K) -> Result<Option<V>>
pub fn get(&self, key: &K) -> Result<Option<V>>
Looks up key, returning Ok(None) if absent, or Err if the lookup
fails in the C++ runtime (e.g. key is not hashable) or the stored value
cannot be converted to V. The map is immutable, so the lookup
(existence check then ffi.MapGetItem) cannot race with itself.
Passing a key whose type does not match the map’s key type is
undefined: the result is unspecified — it currently reads as absent
(Ok(None)) because a pure lookup hashes the key rather than retrieving
one, so the mismatch cannot be surfaced as an Err the way a value
mismatch (or Map::iter, which retrieves keys) is. Debug builds assert
against this misuse.
Trait Implementations§
Source§impl<K, V> AnyCompatible for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
impl<K, V> AnyCompatible for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
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
Source§unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
Source§unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
Source§fn get_mismatch_type_info(data: &TVMFFIAny) -> String
fn get_mismatch_type_info(data: &TVMFFIAny) -> String
Source§impl<K: AnyCompatible, V: AnyCompatible> ArgIntoRef for &Map<K, V>
impl<K: AnyCompatible, V: AnyCompatible> ArgIntoRef for &Map<K, V>
Source§impl<K: AnyCompatible, V: AnyCompatible> ArgIntoRef for Map<K, V>
impl<K: AnyCompatible, V: AnyCompatible> ArgIntoRef for Map<K, V>
Source§impl<K, V> Debug for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
impl<K, V> Debug for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
Source§impl<K, V> Default for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
impl<K, V> Default for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
Source§impl<K, V> FromIterator<(K, V)> for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
impl<K, V> FromIterator<(K, V)> for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
Source§fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
Duplicate keys follow C++ ffi.Map semantics: a later pair overwrites an
earlier one, so the resulting map may be smaller than the iterator.
Source§impl<'a, K: AnyCompatible, V: AnyCompatible> IntoArgHolder for &'a Map<K, V>
impl<'a, K: AnyCompatible, V: AnyCompatible> IntoArgHolder for &'a Map<K, V>
Source§impl<K: AnyCompatible, V: AnyCompatible> IntoArgHolder for Map<K, V>
impl<K: AnyCompatible, V: AnyCompatible> IntoArgHolder for Map<K, V>
Source§impl<K, V> IntoIterator for &Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
impl<K, V> IntoIterator for &Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
Source§impl<K, V> ObjectRefCore for Map<K, V>
impl<K, V> ObjectRefCore for Map<K, V>
Source§impl<K, V> TryFrom<Any> for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
impl<K, V> TryFrom<Any> for Map<K, V>where
K: AnyCompatible,
V: AnyCompatible,
Auto Trait Implementations§
impl<K, V> Freeze for Map<K, V>
impl<K, V> RefUnwindSafe for Map<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> !Send for Map<K, V>
impl<K, V> !Sync for Map<K, V>
impl<K, V> Unpin for Map<K, V>
impl<K, V> UnsafeUnpin for Map<K, V>
impl<K, V> UnwindSafe for Map<K, V>where
K: UnwindSafe,
V: UnwindSafe,
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,
Source§impl<T> ObjectRefCast for Twhere
T: ObjectRefCore + AnyCompatible,
impl<T> ObjectRefCast for Twhere
T: ObjectRefCore + AnyCompatible,
Source§fn try_cast<B>(self) -> Result<B>where
B: ObjectRefCore + AnyCompatible,
fn try_cast<B>(self) -> Result<B>where
B: ObjectRefCore + AnyCompatible,
self and rewrap the underlying object as B without copying.