Enum erlang_term::term::Term
source · pub enum Term {
}
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
impl Term
pub fn from_bytes(input: &[u8]) -> Result<Term, NomErr<Error<&[u8]>>>
pub fn to_bytes(self) -> Vec<u8> ⓘ
pub fn as_type(&self) -> RawTermType
pub fn as_general_type(&self) -> RawTermGeneralType
pub fn is_byte(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_atom(&self) -> bool
pub fn is_tuple(&self) -> bool
sourcepub fn is_pair_tuple(&self) -> bool
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());
pub fn is_list(&self) -> bool
sourcepub fn is_string_tuple_pair(&self) -> bool
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());
pub fn as_bool(self) -> Option<bool>
pub fn as_nil(self) -> Option<()>
pub fn as_byte(self) -> Option<u8>
pub fn as_int(self) -> Option<i32>
pub fn as_float(self) -> Option<f64>
pub fn as_atom(self) -> Option<String>
pub fn as_string(self) -> Option<String>
pub fn as_bytes(self) -> Option<Vec<u8>>
pub fn as_charlist(self) -> Option<Vec<u8>>
pub fn as_big_int(self) -> Option<BigInt>
pub fn as_keyword(self) -> Option<Keylist<String, Term>>
pub fn as_list(self) -> Option<Vec<Term>>
pub fn as_tuple(self) -> Option<Vec<Term>>
pub fn as_map(self) -> Option<HashMap<Term, Term>>
Trait Implementations§
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>,
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
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>,
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
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>,
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
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>,
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
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>,
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
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>,
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
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>,
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
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>,
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
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>,
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
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>,
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
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>,
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
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>,
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
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>,
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
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 Ord for Term
impl Ord for Term
source§impl PartialEq<Term> for Term
impl PartialEq<Term> for Term
source§impl PartialOrd<Term> for Term
impl PartialOrd<Term> for Term
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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