Context

Struct Context 

Source
pub struct Context {
    pub globals: BTreeMap<String, Box<dyn Any>>,
}
Expand description

Virtual machine context

Fields§

§globals: BTreeMap<String, Box<dyn Any>>

The global variables queryable by name

Implementations§

Source§

impl Context

Source

pub fn new() -> Self

Create an empty context

Source

pub fn set_global<K: ToString, V: Any>(&mut self, key: K, value: V)

Set a global variable

Source

pub fn replace_global<K: ToString, V: Any, R: Any>( &mut self, key: K, value: V, ) -> Result<Option<Box<R>>, Trap>

This does the same thing as set_global but attempts to return the variable which was replaced

Source

pub fn get_global<K: AsRef<str>, V: Any>( &self, key: K, ) -> Result<Option<&V>, Trap>

Get a global variable

Source

pub fn get_global_mut<K: AsRef<str>, V: Any>( &mut self, key: K, ) -> Result<Option<&mut V>, Trap>

Get a mutable reference to a global variable

Source

pub fn delete_global<K: AsRef<str>>(&mut self, key: K)

Delete a global variable

Source

pub fn remove_global<K: AsRef<str>, R: Any>( &mut self, key: K, ) -> Result<Option<Box<R>>, Trap>

Does the same thing as delete_global but attempts to return the removed variable

Trait Implementations§

Source§

impl Default for Context

Source§

fn default() -> Context

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.