[−][src]Struct rustler::Term
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.
Methods
impl<'a> Term<'a>
[src]
pub fn atom_to_string(&self) -> NifResult<String>
[src]
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.
impl<'a> Term<'a>
[src]
pub fn into_binary(self) -> NifResult<Binary<'a>>
[src]
impl<'a> Term<'a>
[src]
pub fn list_new_empty(env: Env<'a>) -> Term<'a>
[src]
Returns a new empty list.
pub fn into_list_iterator(self) -> NifResult<ListIterator<'a>>
[src]
Returns an iterator over a list term. See documentation for ListIterator for more information.
Returns None if the term is not a list.
pub fn list_length(self) -> NifResult<usize>
[src]
Returns the length of a list term.
Returns None if the term is not a list.
Elixir equivalent
length(self_term)
pub fn list_get_cell(self) -> NifResult<(Term<'a>, Term<'a>)>
[src]
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}
pub fn list_reverse(self) -> NifResult<Term<'a>>
[src]
Makes a copy of the self list term and reverses it.
Returns Err(Error::BadArg) if the term is not a list.
pub fn list_prepend(self, head: Term<'a>) -> Term<'a>
[src]
Adds head
in a list cell with self
as tail.
impl<'a> Term<'a>
[src]
pub fn map_new(env: Env<'a>) -> Term<'a>
[src]
pub fn map_from_arrays(
env: Env<'a>,
keys: &[Term<'a>],
values: &[Term<'a>]
) -> NifResult<Term<'a>>
[src]
env: Env<'a>,
keys: &[Term<'a>],
values: &[Term<'a>]
) -> NifResult<Term<'a>>
pub fn map_get(self, key: Term) -> NifResult<Term<'a>>
[src]
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)
pub fn map_size(self) -> NifResult<usize>
[src]
Gets the size of a map term.
Returns Err(Error::BadArg) if the term is not a map.
Elixir equivalent
map_size(self_term)
pub fn map_put(self, key: Term<'a>, value: Term<'a>) -> NifResult<Term<'a>>
[src]
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)
pub fn map_remove(self, key: Term<'a>) -> NifResult<Term<'a>>
[src]
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)
pub fn map_update(
self,
key: Term<'a>,
new_value: Term<'a>
) -> NifResult<Term<'a>>
[src]
self,
key: Term<'a>,
new_value: Term<'a>
) -> NifResult<Term<'a>>
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.
impl<'a> Term<'a>
[src]
pub unsafe fn new(env: Env<'a>, inner: NIF_TERM) -> Self
[src]
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.
pub fn as_c_arg(&self) -> NIF_TERM
[src]
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.
pub fn get_env(&self) -> Env<'a>
[src]
pub fn in_env<'b>(&self, env: Env<'b>) -> Term<'b>
[src]
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.
pub fn decode<T>(self) -> NifResult<T> where
T: Decoder<'a>,
[src]
T: Decoder<'a>,
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()?;
pub fn decode_as_binary(self) -> NifResult<Binary<'a>>
[src]
Decodes the Term into Binary
This could be used as a replacement for decode
when decoding Binary from an iolist
is needed.
pub fn to_binary(self) -> OwnedBinary
[src]
impl<'a> Term<'a>
[src]
pub fn get_type(self) -> TermType
[src]
Returns an enum representing which type the term is.
Note that using the individual is_*
functions is more
efficient for checking a single type.
pub fn is_atom(self) -> bool
[src]
pub fn is_binary(self) -> bool
[src]
pub fn is_empty_list(self) -> bool
[src]
pub fn is_exception(self) -> bool
[src]
pub fn is_fun(self) -> bool
[src]
pub fn is_list(self) -> bool
[src]
pub fn is_map(self) -> bool
[src]
pub fn is_number(self) -> bool
[src]
pub fn is_pid(self) -> bool
[src]
pub fn is_port(self) -> bool
[src]
pub fn is_ref(self) -> bool
[src]
pub fn is_tuple(self) -> bool
[src]
Trait Implementations
impl<'a> Clone for Term<'a>
[src]
impl<'a> Copy for Term<'a>
[src]
impl<'a> Debug for Term<'a>
[src]
impl<'a> Decoder<'a> for Term<'a>
[src]
impl<'a> Encoder for Term<'a>
[src]
impl<'a> Eq for Term<'a>
[src]
impl<'a> Ord for Term<'a>
[src]
fn cmp(&self, other: &Term) -> Ordering
[src]
#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'a> PartialEq<Term<'a>> for Atom
[src]
impl<'a> PartialEq<Term<'a>> for Term<'a>
[src]
impl<'a> PartialOrd<Term<'a>> for Term<'a>
[src]
fn partial_cmp(&self, other: &Term<'a>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> Send for Term<'a>
[src]
impl<'a> Sync for Term<'a>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,