pub struct Term<'a> { /* private fields */ }
Expand description

Term is used to represent all erlang terms. Terms are always lifetime limited by a Env.

Term is cloneable and copyable, but it can not exist outside of the lifetime of the Env that owns it.

Implementations

When the term is an atom, this method will return the string representation of it.

If you only need to test for equality, comparing the terms directly is much faster.

Will return None if the term is not an atom.

Returns a new empty list.

Returns an iterator over a list term. See documentation for ListIterator for more information.

Returns None if the term is not a list.

Returns the length of a list term.

Returns None if the term is not a list.

Elixir equivalent
length(self_term)

Unpacks a single cell at the head of a list term, and returns the result as a tuple of (head, tail).

Returns None if the term is not a list.

Elixir equivalent
[head, tail] = self_term
{head, tail}

Makes a copy of the self list term and reverses it.

Returns Err(Error::BadArg) if the term is not a list.

Adds head in a list cell with self as tail.

Constructs a new, empty map term.

Elixir equivalent
%{}

Construct a new map from two vectors

Elixir equivalent
keys = ["foo", "bar"]
values = [1, 2]
List.zip(keys, values) |> Map.new()

Construct a new map from pairs of terms

It is similar to map_from_arrays but receives only one vector with the pairs of (key, value).

Elixir equivalent
Map.new([{"foo", 1}, {"bar", 2}])

Gets the value corresponding to a key in a map term.

Returns Err(Error::BadArg) if the term is not a map or if key doesn’t exist in the map.

Elixir equivalent
Map.get(self_term, key)

Gets the size of a map term.

Returns Err(Error::BadArg) if the term is not a map.

Elixir equivalent
map_size(self_term)

Makes a copy of the self map term and sets key to value. If the value already exists, it is overwritten.

Returns Err(Error::BadArg) if the term is not a map.

Elixir equivalent
Map.put(self_term, key, value)

Makes a copy of the self map term and removes key. If the key doesn’t exist, the original map is returned.

Returns Err(Error::BadArg) if the term is not a map.

Elixir equivalent
Map.delete(self_term, key)

Makes a copy of the self map term where key is set to value.

Returns Err(Error::BadArg) if the term is not a map of if key doesn’t exist.

Create a Term from a raw NIF_TERM.

Unsafe

The caller must ensure that env is the environment that inner belongs to, unless inner is an atom term.

This extracts the raw term pointer. It is usually used in order to obtain a type that can be passed to calls into the erlang vm.

Returns a representation of self in the given Env.

If the term is already is in the provided env, it will be directly returned. Otherwise the term will be copied over.

Decodes the Term into type T.

This should be used as the primary method of extracting the value from a Term.

Examples
let term: Term = ...;
let number: i32 = term.decode()?;

Decodes the Term into Binary

This could be used as a replacement for decode when decoding Binary from an iolist is needed.

Non-portable hash function that only guarantees the same hash for the same term within one Erlang VM instance.

It takes 32-bit salt values and generates hashes within 0..2^32-1.

Portable hash function that gives the same hash for the same Erlang term regardless of machine architecture and ERTS version.

It generates hashes within 0..2^27-1.

Returns an enum representing which type the term is. Note that using the individual is_* functions is more efficient for checking a single type.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.