Struct Map

#[repr(transparent)]
pub struct Map<K = JsValue, V = JsValue> { /* private fields */ }

Implementations

impl Map

fn new() -> Map

The Map object holds key-value pairs. Any value (both objects and primitive values) maybe used as either a key or a value.

Note: Consider using Map::new_typed for typing support.

MDN documentation

impl<K, V> Map<K, V>

fn try_for_each(&self, callback: &mut dyn FnMut(V, K) -> Result<(), JsError>) -> Result<(), JsValue>
where
    dyn FnMut(V, K) -> Result<(), JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue) -> Result<(), JsError>>,

The forEach() method executes a provided function once per each key/value pair in the Map object, in insertion order. (Fallible variation) Note that in Javascript land the Key and Value are reversed compared to normal expectations:

Examples

let js_map = Map::new();
js_map.for_each(&mut |value, key| {
    // Do something here...
})

Note: Consider using Map::try_for_each if the callback might throw an error.

MDN documentation

impl<K, V> Map<K, V>

fn get(&self, key: &K) -> V
where
    K: ErasableGenericBorrow<JsValue>,
    V: ErasableGenericOwn<JsValue>,

The get() method returns a specified element from a Map object. Returns undefined if the key is not found.

Note: Consider using Map::get_checked to get an Option<V> instead.

MDN documentation

impl<K, V> Map<K, V>

fn has(&self, key: &K) -> bool
where
    K: ErasableGenericBorrow<JsValue>,

The has() method returns a boolean indicating whether an element with the specified key exists or not.

MDN documentation

impl<K, V> Map<K, V>

fn new_typed() -> Map<K, V>
where
    Map<K, V>: ErasableGenericOwn<Map<JsValue, JsValue>>,

The Map object holds key-value pairs. Any value (both objects and primitive values) maybe used as either a key or a value.

MDN documentation

impl<K, V> Map<K, V>

fn delete(&self, key: &K) -> bool
where
    K: ErasableGenericBorrow<JsValue>,

The delete() method removes the specified element from a Map object.

MDN documentation

impl<K, V> Map<K, V>

fn set(&self, key: &K, value: &V) -> Map<K, V>
where
    K: ErasableGenericBorrow<JsValue>,
    V: ErasableGenericBorrow<JsValue>,
    Map<K, V>: ErasableGenericOwn<Map<JsValue, JsValue>>,

The set() method adds or updates an element with a specified key and value to a Map object.

MDN documentation

impl<K, V> Map<K, V>

fn new_from_entries<I>(entries: &I) -> Map<K, V>
where
    I: Iterable<Item = ArrayTuple<(K, V)>> + ErasableGenericBorrow<JsValue>,
    Map<K, V>: ErasableGenericOwn<Map<JsValue, JsValue>>,

The Map object holds key-value pairs. Any value (both objects and primitive values) maybe used as either a key or a value.

MDN documentation

impl<K, V> Map<K, V>

fn for_each(&self, callback: &mut dyn FnMut(V, K))
where
    dyn FnMut(V, K): ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue)>,

The forEach() method executes a provided function once per each key/value pair in the Map object, in insertion order. Note that in Javascript land the Key and Value are reversed compared to normal expectations:

Examples

let js_map = Map::new();
js_map.for_each(&mut |value, key| {
    // Do something here...
})

MDN documentation

impl<K, V> Map<K, V>

fn get_checked(&self, key: &K) -> Option<V>
where
    K: ErasableGenericBorrow<JsValue>,
    Option<V>: ErasableGenericOwn<Option<JsValue>>,

The get() method returns a specified element from a Map object. Returns None if the key is not found.

MDN documentation

impl<K, V> Map<K, V>

fn size(&self) -> u32

The value of size is an integer representing how many entries the Map object has. A set accessor function for size is undefined; you can not change this property.

MDN documentation

impl<K, V> Map<K, V>

fn clear(&self)

The clear() method removes all elements from a Map object.

MDN documentation

impl<K, V> Map<K, V> where K: FromWasmAbi, V: FromWasmAbi,

fn keys(&self) -> Iterator<K>
where
    Iterator<K>: ErasableGenericOwn<Iterator<JsValue>>,

The keys() method returns a new Iterator object that contains the keys for each element in the Map object in insertion order.

MDN documentation

impl<K, V> Map<K, V> where K: JsGeneric, V: FromWasmAbi + JsGeneric,

fn entries_typed(&self) -> Iterator<ArrayTuple<(K, V)>>
where
    Iterator<ArrayTuple<(K, V)>>: ErasableGenericOwn<Iterator<ArrayTuple<(JsValue, JsValue)>>>,

The entries() method returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order.

MDN documentation

impl<K, V> Map<K, V> where V: FromWasmAbi,

fn entries(&self) -> Iterator

The entries() method returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order.

MDN documentation

impl<K, V> Map<K, V> where V: FromWasmAbi,

fn values(&self) -> Iterator<V>
where
    Iterator<V>: ErasableGenericOwn<Iterator<JsValue>>,

The values() method returns a new Iterator object that contains the values for each element in the Map object in insertion order.

MDN documentation

Trait Implementations

impl Default for Map<JsValue, JsValue>

fn default() -> Self

impl From<JsValue> for Map

fn from(obj: JsValue) -> Self

impl<K, V> AsRef<JsValue> for Map<K, V>

fn as_ref(&self) -> &JsValue

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

fn as_ref(&self) -> &Map<K, V>

impl<K, V> AsRef<Object> for Map<K, V>

fn as_ref(&self) -> &Object

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

type Target = Object;
fn deref(&self) -> &Object

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

type Repr = JsValue;

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

type Abi = <JsValue as FromWasmAbi>::Abi;
unsafe fn from_abi(js: Self::Abi) -> Self

impl<K, V> IntoJsGeneric for Map<K, V> where Map<K, V>: JsGeneric,

type JsCanon = Map<K, V>;
fn to_js(self) -> Map<K, V>

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

type Abi = <JsValue as IntoWasmAbi>::Abi;
fn into_abi(self) -> Self::Abi

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

type Item = ArrayTuple<(K, V)>;

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

fn instanceof(val: &JsValue) -> bool
fn unchecked_from_js(val: JsValue) -> Self
fn unchecked_from_js_ref(val: &JsValue) -> &Self

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

type Abi = <JsValue as LongRefFromWasmAbi>::Abi;
type Anchor = Map<K, V>;
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

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

fn is_none(abi: &Self::Abi) -> bool

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

fn none() -> Self::Abi

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

type Resolution = Map<K, V>;

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

type Abi = <JsValue as RefFromWasmAbi>::Abi;
type Anchor = ManuallyDrop<Map<K, V>>;
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

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

fn describe()

impl<K, V, __UpcastTarget0, __UpcastTarget1> UpcastFrom<Map<K, V>> for Map<__UpcastTarget0, __UpcastTarget1> where __UpcastTarget0: UpcastFrom<K>, __UpcastTarget1: UpcastFrom<V>,

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

fn clone(&self) -> Self

impl<K: Debug, V: Debug> Debug for Map<K, V>

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

impl<K: Eq, V: Eq> Eq for Map<K, V>

impl<K: PartialEq, V: PartialEq> PartialEq for Map<K, V>

fn eq(&self, other: &Self) -> bool

impl<K: PartialEq, V: PartialEq> StructuralPartialEq for Map<K, V>

Auto Trait Implementations

impl<K, V> Freeze for Map<K, V> where PhantomData<(K, V)>: Freeze,

impl<K, V> RefUnwindSafe for Map<K, V> where PhantomData<(K, V)>: RefUnwindSafe,

impl<K, V> Send for Map<K, V> where PhantomData<(K, V)>: Send,

impl<K, V> Sync for Map<K, V> where PhantomData<(K, V)>: Sync,

impl<K, V> Unpin for Map<K, V> where PhantomData<(K, V)>: Unpin,

impl<K, V> UnsafeUnpin for Map<K, V> where PhantomData<(K, V)>: UnsafeUnpin,

impl<K, V> UnwindSafe for Map<K, V> where PhantomData<(K, V)>: UnwindSafe,

Blanket Implementations

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

impl<S, T> Upcast<T> for Map<K, V> where T: UpcastFrom<S> + ?Sized, S: ?Sized,

impl<T> Any for Map<K, V> where T: 'static + ?Sized,

impl<T> Borrow<T> for Map<K, V> where T: ?Sized,

impl<T> BorrowMut<T> for Map<K, V> where T: ?Sized,

impl<T> CloneToUninit for Map<K, V> where T: Clone,

impl<T> From<T> for Map<K, V>

impl<T> JsGeneric for Map<K, V> where T: ErasableGeneric<Repr = JsValue> + UpcastFrom<T> + Upcast<JsValue> + JsCast + 'static,

impl<T> ReturnWasmAbi for Map<K, V> where T: IntoWasmAbi,

impl<T> ToOwned for Map<K, V> where T: Clone,

impl<T> TryFromJsValue for Map<K, V> where T: JsCast,

impl<T> VectorFromWasmAbi for Map<K, V> where T: ErasableGeneric<Repr = JsValue> + WasmDescribe,

impl<T> VectorIntoWasmAbi for Map<K, V> where T: ErasableGeneric<Repr = JsValue> + WasmDescribe,

impl<T> VectorRefIntoWasmAbi for Map<K, V> where &'a T: for<'a> Into<JsValue>,

impl<T, U> Into<U> for Map<K, V> where U: From<T>,

impl<T, U> TryFrom<U> for Map<K, V> where U: Into<T>,

impl<T, U> TryInto<U> for Map<K, V> where U: TryFrom<T>,