Struct endbasic_core::syms::Symbols
source · [−]pub struct Symbols { /* private fields */ }
Expand description
Storage for all symbols that exist at runtime.
Implementations
sourceimpl Symbols
impl Symbols
sourcepub fn add_command(&mut self, command: Rc<dyn Command>)
pub fn add_command(&mut self, command: Rc<dyn Command>)
Registers the given builtin command.
Given that commands cannot be defined at runtime, specifying a non-unique name results in a panic.
sourcepub fn add_function(&mut self, function: Rc<dyn Function>)
pub fn add_function(&mut self, function: Rc<dyn Function>)
Registers the given builtin function.
Given that functions cannot be defined at runtime, specifying a non-unique name results in a panic.
sourcepub fn as_hashmap(&self) -> &HashMap<String, Symbol>
pub fn as_hashmap(&self) -> &HashMap<String, Symbol>
Returns the mapping of all symbols.
sourcepub fn dim(&mut self, name: &str, vartype: VarType) -> Result<()>
pub fn dim(&mut self, name: &str, vartype: VarType) -> Result<()>
Defines a new variable name
of type vartype
. The variable must not yet exist.
sourcepub fn dim_array(
&mut self,
name: &str,
subtype: VarType,
dimensions: Vec<usize>
) -> Result<()>
pub fn dim_array(
&mut self,
name: &str,
subtype: VarType,
dimensions: Vec<usize>
) -> Result<()>
Defines a new array name
of type subtype
with dimensions
. The array must not yet
exist, and the name may not overlap function or variable names.
sourcepub fn get(&self, vref: &VarRef) -> Result<Option<&Symbol>>
pub fn get(&self, vref: &VarRef) -> Result<Option<&Symbol>>
Obtains the value of a symbol or None
if it is not defined.
Returns an error if the type annotation in the symbol reference does not match its type.
sourcepub fn get_mut(&mut self, vref: &VarRef) -> Result<Option<&mut Symbol>>
pub fn get_mut(&mut self, vref: &VarRef) -> Result<Option<&mut Symbol>>
Obtains the value of a symbol or None
if it is not defined.
Returns an error if the type annotation in the symbol reference does not match its type.
sourcepub fn get_var(&self, vref: &VarRef) -> Result<&Value>
pub fn get_var(&self, vref: &VarRef) -> Result<&Value>
Obtains the value of a variable.
Returns an error if the variable is not defined, if the referenced symbol is not a variable, or if the type annotation in the variable reference does not match the type of the value that the variable contains.
sourcepub fn qualify_varref(&self, vref: &VarRef) -> Result<VarRef>
pub fn qualify_varref(&self, vref: &VarRef) -> Result<VarRef>
Adds a type annotation to the symbol reference if the symbol is already defined and the reference lacks one.
sourcepub fn set_var(&mut self, vref: &VarRef, value: Value) -> Result<()>
pub fn set_var(&mut self, vref: &VarRef, value: Value) -> Result<()>
Sets the value of a variable.
If vref
contains a type annotation, the type of the value must be compatible with that
type annotation.
If the variable is already defined, then the type of the new value must be compatible with the existing variable. In other words: a variable cannot change types while it’s alive.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Symbols
impl !Send for Symbols
impl !Sync for Symbols
impl Unpin for Symbols
impl !UnwindSafe for Symbols
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more