Struct rustler::NifTerm
[−]
[src]
pub struct NifTerm<'a> { /* fields omitted */ }
NifTerm is used to represent all erlang terms. Terms are always lifetime limited by a NifEnv.
NifTerm is cloneable and copyable, but it can not exist outside of the lifetime of the NifEnv that owns it.
Methods
impl<'a> NifTerm<'a>
[src]
fn atom_to_string(&self) -> NifResult<String>
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> NifTerm<'a>
[src]
fn into_binary(self) -> NifResult<NifBinary<'a>>
impl<'a> NifTerm<'a>
[src]
fn into_list_iterator(self) -> NifResult<NifListIterator<'a>>
Returns an iterator over a list term. See documentation for NifListIterator for more information.
Returns None if the term is not a list.
fn list_length(self) -> NifResult<usize>
Returns the length of a list term.
Returns None if the term is not a list.
Elixir equivalent
length(self_term)
fn list_get_cell(self) -> NifResult<(NifTerm<'a>, NifTerm<'a>)>
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}
fn list_reverse(self) -> NifResult<NifTerm<'a>>
Makes a copy of the self list term and reverses it.
Returns Err(NifError::BadArg) if the term is not a list.
fn list_prepend(self, head: NifTerm<'a>) -> NifTerm<'a>
Adds head
in a list cell with self
as tail.
impl<'a> NifTerm<'a>
[src]
fn map_get(self, key: NifTerm) -> NifResult<NifTerm<'a>>
Gets the value corresponding to a key in a map term.
Returns Err(NifError::BadArg) if the term is not a map or if key doesn't exist in the map.
Elixir equivalent
Map.get(self_term, key)
fn map_size(self) -> NifResult<usize>
Gets the size of a map term.
Returns Err(NifError::BadArg) if the term is not a map.
Elixir equivalent
map_size(self_term)
fn map_put(self, key: NifTerm<'a>, value: NifTerm<'a>) -> NifResult<NifTerm<'a>>
Makes a copy of the self map term and sets key to value. If the value already exists, it is overwritten.
Returns Err(NifError::BadArg) if the term is not a map.
Elixir equivalent
Map.put(self_term, key, value)
fn map_remove(self, key: NifTerm<'a>) -> NifResult<NifTerm<'a>>
Makes a copy of the self map term and removes key. If the key doesn't exist, the original map is returned.
Returns Err(NifError::BadArg) if the term is not a map.
Elixir equivalent
Map.delete(self_term, key)
fn map_update(
self,
key: NifTerm<'a>,
new_value: NifTerm<'a>
) -> NifResult<NifTerm<'a>>
self,
key: NifTerm<'a>,
new_value: NifTerm<'a>
) -> NifResult<NifTerm<'a>>
Makes a copy of the self map term where key is set to value.
Returns Err(NifError::BadArg) if the term is not a map of if key doesn't exist.
impl<'a> NifTerm<'a>
[src]
unsafe fn new(env: NifEnv<'a>, inner: NIF_TERM) -> Self
Create a NifTerm
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.
fn as_c_arg(&self) -> NIF_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.
fn get_env(&self) -> NifEnv<'a>
fn in_env<'b>(&self, env: NifEnv<'b>) -> NifTerm<'b>
Returns a representation of self in the given NifEnv.
If the term is already is in the provided env, it will be directly returned. Otherwise the term will be copied over.
fn decode<T>(self) -> NifResult<T> where
T: NifDecoder<'a>,
T: NifDecoder<'a>,
Decodes the NifTerm into type T.
This should be used as the primary method of extracting the value from a NifTerm.
Examples
let term: NifTerm = ...; let number: i32 = try!(term.decode());
fn to_binary(self) -> NifBinary<'a>
impl<'a> NifTerm<'a>
[src]
fn get_type(self) -> TermType
Returns an enum representing which type the term is.
Note that using the individual is_*
functions is more
efficient for checking a single type.
fn is_atom(self) -> bool
fn is_binary(self) -> bool
fn is_empty_list(self) -> bool
fn is_exception(self) -> bool
fn is_fun(self) -> bool
fn is_list(self) -> bool
fn is_map(self) -> bool
fn is_pid(self) -> bool
fn is_port(self) -> bool
fn is_ref(self) -> bool
fn is_tuple(self) -> bool
Trait Implementations
impl<'a> NifEncoder for NifTerm<'a>
[src]
impl<'a> NifDecoder<'a> for NifTerm<'a>
[src]
impl<'a> Clone for NifTerm<'a>
[src]
fn clone(&self) -> NifTerm<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more