Enum erlang_term::term::Term

source ·
pub enum Term {
Show 15 variants Byte(u8), Int(i32), Float(OrderedFloat<f64>), String(String), Atom(String), Bytes(Vec<u8>), Bool(bool), Nil, BigInt(BigInt), Charlist(Vec<u8>), Map(HashMap<Term, Term>), Keyword(Keylist<String, Term>), List(Vec<Term>), Tuple(Vec<Term>), Other(RawTerm),
}
Expand description

Higher level Elixir types

These can be created by using the Term::from methods or creating them directly.


let string = Term::from("ok");
let atom = Term::Atom("ok".to_string());

assert!(string.is_string());
assert!(atom.is_atom());
assert_ne!(string, atom);

The Term::as_* will unwrap the Term into a specific type if the Term is that type


let atom = Term::Atom("ok".to_string());
assert_eq!(Some("ok".to_string()), atom.as_atom());

let atom = Term::Atom("ok".to_string());
assert_eq!(None, atom.as_string());

Convert to RawTerm


let term = Term::from("testing");
let raw_term = RawTerm::from(term);

assert_eq!(RawTerm::Binary(vec![116, 101, 115, 116, 105, 110, 103]), raw_term);

Convert from RawTerm


let raw_term = RawTerm::Binary(vec![116, 101, 115, 116, 105, 110, 103]);
let term = Term::from(raw_term);

assert_eq!(Some("testing".to_string()), term.as_string());

Variants§

§

Byte(u8)

§

Int(i32)

§

Float(OrderedFloat<f64>)

§

String(String)

§

Atom(String)

§

Bytes(Vec<u8>)

§

Bool(bool)

§

Nil

§

BigInt(BigInt)

§

Charlist(Vec<u8>)

§

Map(HashMap<Term, Term>)

§

Keyword(Keylist<String, Term>)

§

List(Vec<Term>)

§

Tuple(Vec<Term>)

§

Other(RawTerm)

Implementations§

source§

impl Term

source

pub fn from_bytes(input: &[u8]) -> Result<Term, NomErr<Error<&[u8]>>>

source

pub fn to_bytes(self) -> Vec<u8>

source

pub fn as_type(&self) -> RawTermType

source

pub fn as_general_type(&self) -> RawTermGeneralType

source

pub fn is_byte(&self) -> bool

source

pub fn is_string(&self) -> bool

source

pub fn is_atom(&self) -> bool

source

pub fn is_tuple(&self) -> bool

source

pub fn is_pair_tuple(&self) -> bool

Check if the Term is a tuple of length 2

let term = Term::from((1, 2));
assert!(term.is_pair_tuple());
source

pub fn is_list(&self) -> bool

source

pub fn is_string_tuple_pair(&self) -> bool

Check if the Term is of the form ("string", any)

let term = Term::from(("test", 1));
assert!(term.is_string_tuple_pair());
let term = Term::from((1, 2));
assert!(!term.is_string_tuple_pair());
source

pub fn as_bool(self) -> Option<bool>

source

pub fn as_nil(self) -> Option<()>

source

pub fn as_byte(self) -> Option<u8>

source

pub fn as_int(self) -> Option<i32>

source

pub fn as_float(self) -> Option<f64>

source

pub fn as_atom(self) -> Option<String>

source

pub fn as_string(self) -> Option<String>

source

pub fn as_bytes(self) -> Option<Vec<u8>>

source

pub fn as_charlist(self) -> Option<Vec<u8>>

source

pub fn as_big_int(self) -> Option<BigInt>

source

pub fn as_keyword(self) -> Option<Keylist<String, Term>>

source

pub fn as_list(self) -> Option<Vec<Term>>

source

pub fn as_tuple(self) -> Option<Vec<Term>>

source

pub fn as_map(self) -> Option<HashMap<Term, Term>>

source

pub fn as_string_map(self) -> Option<HashMap<String, Term>>

Unwrap and convert the term into a HashMap<String, Term> if the term is a map and all the keys are strings Note that this will create a new map, so for one-offs you should use the Term::as_map function

source

pub fn as_atom_map(self) -> Option<HashMap<String, Term>>

Unwrap and convert the term into a HashMap<String, Term> if the term is a map and all the keys are atoms Note that this will create a new map, so for one-offs you should use the Term::as_map function

Trait Implementations§

source§

impl Clone for Term

source§

fn clone(&self) -> Term

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Term

source§

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

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

impl Display for Term

source§

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

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

impl From<&str> for Term

source§

fn from(input: &str) -> Term

Converts to this type from the input type.
source§

impl From<()> for Term

source§

fn from(_input: ()) -> Term

Converts to this type from the input type.
source§

impl<A> From<(A,)> for Termwhere A: Into<Term>,

source§

fn from(input: (A,)) -> Self

Converts to this type from the input type.
source§

impl<A, B> From<(A, B)> for Termwhere A: Into<Term>, B: Into<Term>,

source§

fn from(input: (A, B)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C> From<(A, B, C)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>,

source§

fn from(input: (A, B, C)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D> From<(A, B, C, D)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>,

source§

fn from(input: (A, B, C, D)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E> From<(A, B, C, D, E)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>,

source§

fn from(input: (A, B, C, D, E)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F> From<(A, B, C, D, E, F)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G> From<(A, B, C, D, E, F, G)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G, H> From<(A, B, C, D, E, F, G, H)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>, H: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G, H)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G, H, I> From<(A, B, C, D, E, F, G, H, I)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>, H: Into<Term>, I: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G, H, I)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G, H, I, J> From<(A, B, C, D, E, F, G, H, I, J)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>, H: Into<Term>, I: Into<Term>, J: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G, H, I, J)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G, H, I, J, K> From<(A, B, C, D, E, F, G, H, I, J, K)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>, H: Into<Term>, I: Into<Term>, J: Into<Term>, K: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G, H, I, J, K)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G, H, I, J, K, L> From<(A, B, C, D, E, F, G, H, I, J, K, L)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>, H: Into<Term>, I: Into<Term>, J: Into<Term>, K: Into<Term>, L: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G, H, I, J, K, L)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M> From<(A, B, C, D, E, F, G, H, I, J, K, L, M)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>, H: Into<Term>, I: Into<Term>, J: Into<Term>, K: Into<Term>, L: Into<Term>, M: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G, H, I, J, K, L, M)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N> From<(A, B, C, D, E, F, G, H, I, J, K, L, M, N)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>, H: Into<Term>, I: Into<Term>, J: Into<Term>, K: Into<Term>, L: Into<Term>, M: Into<Term>, N: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G, H, I, J, K, L, M, N)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O> From<(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>, H: Into<Term>, I: Into<Term>, J: Into<Term>, K: Into<Term>, L: Into<Term>, M: Into<Term>, N: Into<Term>, O: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)) -> Self

Converts to this type from the input type.
source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> From<(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)> for Termwhere A: Into<Term>, B: Into<Term>, C: Into<Term>, D: Into<Term>, E: Into<Term>, F: Into<Term>, G: Into<Term>, H: Into<Term>, I: Into<Term>, J: Into<Term>, K: Into<Term>, L: Into<Term>, M: Into<Term>, N: Into<Term>, O: Into<Term>, P: Into<Term>,

source§

fn from(input: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)) -> Self

Converts to this type from the input type.
source§

impl<K: Into<Term>, V: Into<Term>> From<HashMap<K, V, RandomState>> for Term

source§

fn from(input: HashMap<K, V>) -> Term

Converts to this type from the input type.
source§

impl From<RawTerm> for Term

source§

fn from(term: RawTerm) -> Self

Converts to this type from the input type.
source§

impl From<String> for Term

source§

fn from(input: String) -> Term

Converts to this type from the input type.
source§

impl From<Term> for RawTerm

source§

fn from(term: Term) -> RawTerm

Converts to this type from the input type.
source§

impl<T: Into<Term>> From<Vec<T, Global>> for Term

source§

fn from(input: Vec<T>) -> Term

Converts to this type from the input type.
source§

impl From<bool> for Term

source§

fn from(input: bool) -> Term

Converts to this type from the input type.
source§

impl From<f32> for Term

source§

fn from(input: f32) -> Term

Converts to this type from the input type.
source§

impl From<f64> for Term

source§

fn from(input: f64) -> Term

Converts to this type from the input type.
source§

impl From<i128> for Term

source§

fn from(input: i128) -> Term

Converts to this type from the input type.
source§

impl From<i16> for Term

source§

fn from(input: i16) -> Term

Converts to this type from the input type.
source§

impl From<i32> for Term

source§

fn from(input: i32) -> Term

Converts to this type from the input type.
source§

impl From<i64> for Term

source§

fn from(input: i64) -> Term

Converts to this type from the input type.
source§

impl From<i8> for Term

source§

fn from(input: i8) -> Term

Converts to this type from the input type.
source§

impl From<u128> for Term

source§

fn from(input: u128) -> Term

Converts to this type from the input type.
source§

impl From<u16> for Term

source§

fn from(input: u16) -> Term

Converts to this type from the input type.
source§

impl From<u32> for Term

source§

fn from(input: u32) -> Term

Converts to this type from the input type.
source§

impl From<u64> for Term

source§

fn from(input: u64) -> Term

Converts to this type from the input type.
source§

impl From<u8> for Term

source§

fn from(input: u8) -> Term

Converts to this type from the input type.
source§

impl From<usize> for Term

source§

fn from(input: usize) -> Term

Converts to this type from the input type.
source§

impl Hash for Term

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

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

impl Ord for Term

source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl PartialEq<Term> for Term

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Term> for Term

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 · source§

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

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

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

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

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

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

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

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

impl Eq for Term

source§

impl StructuralPartialEq for Term

Auto Trait Implementations§

§

impl RefUnwindSafe for Term

§

impl Send for Term

§

impl Sync for Term

§

impl Unpin for Term

§

impl UnwindSafe for Term

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.