pub struct Context { /* private fields */ }Expand description
structure that contains all the data at the count level, saves the variables, tokens, functions and keys Use example :
use procc_ll::context::Context;
let mut context = Context::new();
context.push_key("key".to_owned(), |token, prog| {
prog.exec(&token);
procc_ll::Values::Null
});Implementations§
Source§impl Context
impl Context
Sourcepub fn token_index(&self, tok: &str) -> Option<usize>
pub fn token_index(&self, tok: &str) -> Option<usize>
Localize the index in the list of tokens of the token
§PANICS
Return a panic if the token is not registered on the context
Sourcepub fn push_token(&mut self, tok: Box<dyn Token>)
pub fn push_token(&mut self, tok: Box<dyn Token>)
Register a new token in te context
Sourcepub fn push_memory(&mut self, key: &str, tok: Values)
pub fn push_memory(&mut self, key: &str, tok: Values)
Push a new data on the memory
Sourcepub fn push_key(
&mut self,
key: String,
tok: impl Fn(String, &mut Program) -> Values + 'static,
)
pub fn push_key( &mut self, key: String, tok: impl Fn(String, &mut Program) -> Values + 'static, )
Register a new key
Sourcepub fn push_function(
&mut self,
name: String,
func: impl Fn(Vec<Values>, &mut Program) -> Values + 'static,
)
pub fn push_function( &mut self, name: String, func: impl Fn(Vec<Values>, &mut Program) -> Values + 'static, )
Add a new function
pub fn get_token(&self, idx: usize) -> Rc<RefCell<Box<dyn Token + 'static>>>
pub fn get_memory(&self, key: &str) -> Values
pub fn get_key(&self, key: &str) -> Arc<dyn Fn(String, &mut Program) -> Values>
pub fn get_function( &self, key: &str, ) -> Arc<dyn Fn(Vec<Values>, &mut Program) -> Values>
pub fn has_token(&self, idx: usize) -> bool
pub fn has_memory(&self, key: &str) -> bool
pub fn has_key(&self, key: &str) -> bool
pub fn has_function(&self, key: &str) -> bool
pub fn gifs_token( &self, idx: usize, ) -> Option<Rc<RefCell<Box<dyn Token + 'static>>>>
pub fn gifs_memory(&self, key: &str) -> Option<Values>
pub fn gifs_key( &self, key: &str, ) -> Option<Arc<dyn Fn(String, &mut Program) -> Values>>
pub fn gifs_function( &self, key: &str, ) -> Option<Arc<dyn Fn(String, &mut Program) -> Values>>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl !Send for Context
impl !Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
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