Skip to main content

Map

Struct Map 

Source
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>

Source

pub fn new() -> Self

Creates a new, empty map (via an ffi.Map() call to the C++ runtime).

Source

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.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no entries.

Source

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.

Source

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.

Source

pub fn iter(&self) -> MapItems<K, V>

Returns an iterator over the (key, value) pairs of the map.

Source

pub fn keys(&self) -> MapKeys<K>

Returns an iterator over the keys of the map.

Source

pub fn values(&self) -> MapValues<V>

Returns an iterator over the values of the map.

Trait Implementations§

Source§

impl<K, V> AnyCompatible for Map<K, V>

Source§

fn type_str() -> String

the type string of the type
Source§

unsafe fn check_any_strict(data: &TVMFFIAny) -> bool

Source§

unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)

the value to copy to TVMFFIAny
Source§

unsafe fn move_to_any(src: Self, data: &mut TVMFFIAny)

consume the value to move to Any
Source§

unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self

Copy value from TVMFFIAny after checking caller must ensure that the value is compatible with the type
Source§

unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self

the value to move from TVMFFIAny NOTE: pay very careful attention to avoid memory leak! Read more
Source§

unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>

try to cast the value from AnyView
Source§

fn get_mismatch_type_info(data: &TVMFFIAny) -> String

Get the type key of a type when TryCastFromAnyView fails.
Source§

impl<K: AnyCompatible, V: AnyCompatible> ArgIntoRef for &Map<K, V>

Source§

type Target = Map<K, V>

Source§

fn to_ref(&self) -> &Self::Target

Source§

impl<K: AnyCompatible, V: AnyCompatible> ArgIntoRef for Map<K, V>

Source§

type Target = Map<K, V>

Source§

fn to_ref(&self) -> &Self::Target

Source§

impl<K, V> Clone for Map<K, V>

Source§

fn clone(&self) -> Self

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<K, V> Debug for Map<K, V>

Source§

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

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

impl<K, V> Default for Map<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, V> Deref for Map<K, V>

Source§

type Target = MapObj

The resulting type after dereferencing.
Source§

fn deref(&self) -> &MapObj

Dereferences the value.
Source§

impl<K, V> FromIterator<(K, V)> for Map<K, V>

Source§

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>

Source§

type Target = &'a Map<K, V>

Source§

fn into_arg_holder(self) -> Self::Target

Source§

impl<K: AnyCompatible, V: AnyCompatible> IntoArgHolder for Map<K, V>

Source§

type Target = Map<K, V>

Source§

fn into_arg_holder(self) -> Self::Target

Source§

impl<K, V> IntoIterator for &Map<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = MapIter<(K, V)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, V> ObjectRefCore for Map<K, V>

Source§

impl<K, V> TryFrom<Any> for Map<K, V>

Source§

type Error = Error

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

fn try_from(value: Any) -> Result<Self>

Performs the conversion.
Source§

impl<'a, K, V> TryFrom<AnyView<'a>> for Map<K, V>

Source§

type Error = Error

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

fn try_from(value: AnyView<'a>) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl<K, V> Freeze for Map<K, V>

§

impl<K, V> RefUnwindSafe for Map<K, V>

§

impl<K, V> !Send for Map<K, V>

§

impl<K, V> !Sync for Map<K, V>

§

impl<K, V> Unpin for Map<K, V>
where K: Unpin, V: Unpin,

§

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> 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
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> ObjectRefCast for T

Source§

fn try_cast<B>(self) -> Result<B>

Consume self and rewrap the underlying object as B without copying.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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, 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.