Skip to main content

Map

Struct Map 

Source
pub struct Map<'id> { /* private fields */ }
Expand description

An Erlang map. Immutable — all mutations return a new map.

Implementations§

Source§

impl<'id> Map<'id>

Source

pub fn from_raw(raw_term: Term) -> Self

Available on crate feature raw only.
Source

pub fn new(env: impl Env<'id>) -> Map<'id>

Create an empty map (enif_make_new_map).

Source

pub fn size(self, env: impl Env<'id>) -> usize

Number of key-value pairs (enif_get_map_size).

Source

pub fn get( self, env: impl Env<'id>, key: impl Term<'id>, ) -> Option<AnyTerm<'id>>

Look up key (enif_get_map_value). None if absent.

Source

pub fn put( self, env: impl Env<'id>, key: impl Term<'id>, value: impl Term<'id>, ) -> Map<'id>

Return a new map with key set to value (enif_make_map_put, insert or replace).

Source

pub fn update( self, env: impl Env<'id>, key: impl Term<'id>, value: impl Term<'id>, ) -> Option<Map<'id>>

Return a new map with key updated to value (enif_make_map_update). None if the key is absent.

Source

pub fn remove(self, env: impl Env<'id>, key: impl Term<'id>) -> Map<'id>

Return a new map with key removed (enif_make_map_remove). Removing a key the map does not contain returns it unchanged.

Source

pub fn is_map(env: impl Env<'id>, term: impl Term<'id>) -> bool

Returns true if term is a map (enif_is_map).

Source

pub fn iter(self, env: impl Env<'id>) -> MapIterator<'id>

Iterate (key, value) pairs in unspecified order.

Trait Implementations§

Source§

impl<'id> Clone for Map<'id>

Source§

fn clone(&self) -> Map<'id>

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<'id> Copy for Map<'id>

Source§

impl Debug for Map<'_>

Source§

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

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

impl<'id> Decoder<'id> for Map<'id>

Accepts a map (enif_is_map); WrongType otherwise.

Source§

fn decode(term: AnyTerm<'id>, env: impl Env<'id>) -> Result<Self, CodecError>

Source§

impl<'id> Encoder<'id> for Map<'id>

Encodes for free by rewrapping the term’s own machine word — an otter term is already an Erlang term. Never fails.

Source§

fn encode(&self, env: impl Env<'id>) -> Result<AnyTerm<'id>, CodecError>

Source§

impl Eq for Map<'_>

Source§

impl<'id> From<Map<'id>> for TypedTerm<'id>

Source§

fn from(v: Map<'id>) -> Self

Converts to this type from the input type.
Source§

impl Ord for Map<'_>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Map<'_>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Map<'_>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'id> Term<'id> for Map<'id>

Source§

fn raw_term(self) -> Term

The raw machine word backing this term.
Source§

fn copy_to<'dst>(self, env: impl Env<'dst>) -> AnyTerm<'dst>
where Self: Sized,

Copy this term into another environment (enif_make_copy), producing a term branded to the destination. The general cross-env copy — distinct from same-brand Encoder (which wraps for free) and from OwnedEnvArena copy_out (the arena exit).

Auto Trait Implementations§

§

impl<'id> !Send for Map<'id>

§

impl<'id> !Sync for Map<'id>

§

impl<'id> Freeze for Map<'id>

§

impl<'id> RefUnwindSafe for Map<'id>

§

impl<'id> Unpin for Map<'id>

§

impl<'id> UnsafeUnpin for Map<'id>

§

impl<'id> UnwindSafe for Map<'id>

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