pub enum TermValue {
}Expand description
Clean, functional ADT for AtomVM terms
This is completely generic - it works with any atom table implementation through the AtomTableOps trait.
Variants§
SmallInt(i32)
Atom(AtomIndex)
Nil
Pid(ProcessId)
Port(PortId)
Reference(RefId)
Tuple(Vec<TermValue>)
List(Box<TermValue>, Box<TermValue>)
Map(Vec<(TermValue, TermValue)>)
Binary(Vec<u8>)
Function(FunctionRef)
Resource(ResourceRef)
Float(f64)
Invalid
Implementations§
Source§impl TermValue
impl TermValue
Sourcepub fn as_list(&self) -> Option<(&TermValue, &TermValue)>
pub fn as_list(&self) -> Option<(&TermValue, &TermValue)>
Pattern match on lists (functional style)
Sourcepub fn is_empty_list(&self) -> bool
pub fn is_empty_list(&self) -> bool
Check if this is an empty list
Sourcepub fn fold_list<T, F>(&self, init: T, f: F) -> T
pub fn fold_list<T, F>(&self, init: T, f: F) -> T
Fold over list elements (functional programming!)
Sourcepub fn filter_list<F>(&self, predicate: F) -> TermValue
pub fn filter_list<F>(&self, predicate: F) -> TermValue
Filter list elements
Sourcepub fn list_length(&self) -> usize
pub fn list_length(&self) -> usize
Get list length
Sourcepub fn list_to_vec(&self) -> Vec<TermValue>
pub fn list_to_vec(&self) -> Vec<TermValue>
Convert list to Vec
Sourcepub fn map_get(&self, key: &TermValue) -> Option<&TermValue>
pub fn map_get(&self, key: &TermValue) -> Option<&TermValue>
Get map value by key (functional lookup)
Sourcepub fn map_set(&self, key: TermValue, value: TermValue) -> TermValue
pub fn map_set(&self, key: TermValue, value: TermValue) -> TermValue
Set map value (returns new map)
Source§impl TermValue
impl TermValue
pub fn int(value: i32) -> Self
Sourcepub fn atom<T: AtomTableOps>(name: &str, table: &T) -> Self
pub fn atom<T: AtomTableOps>(name: &str, table: &T) -> Self
Create atom using any atom table (GENERIC!)
pub fn tuple(elements: Vec<TermValue>) -> Self
pub fn list(elements: Vec<TermValue>) -> Self
pub fn binary(data: Vec<u8>) -> Self
pub fn map(pairs: Vec<(TermValue, TermValue)>) -> Self
pub fn pid(id: u32) -> Self
pub fn port(id: u32) -> Self
pub fn reference(id: u64) -> Self
pub fn float(value: f64) -> Self
Source§impl TermValue
impl TermValue
Sourcepub fn tuple_arity(&self) -> usize
pub fn tuple_arity(&self) -> usize
Extract tuple arity
Sourcepub fn double_ints(&self) -> TermValue
pub fn double_ints(&self) -> TermValue
Example: Convert list of integers to list of their doubles
Sourcepub fn is_atom_str<T: AtomTableOps>(&self, name: &str, table: &T) -> bool
pub fn is_atom_str<T: AtomTableOps>(&self, name: &str, table: &T) -> bool
Check if atom matches string using any atom table (GENERIC!)
Sourcepub fn as_atom_str<T: AtomTableOps>(&self, table: &T) -> Option<String>
pub fn as_atom_str<T: AtomTableOps>(&self, table: &T) -> Option<String>
Get atom as string using any atom table (GENERIC!)
Trait Implementations§
impl StructuralPartialEq for TermValue
Auto Trait Implementations§
impl Freeze for TermValue
impl RefUnwindSafe for TermValue
impl !Send for TermValue
impl !Sync for TermValue
impl Unpin for TermValue
impl UnwindSafe for TermValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more