Struct Machine

Source
pub struct Machine { /* private fields */ }
Expand description

Executes an EndBASIC program and tracks its state.

Implementations§

Source§

impl Machine

Source

pub fn with_signals_chan(signals: (Sender<Signal>, Receiver<Signal>)) -> Self

Constructs a new empty machine with the given signals communication channel.

Source

pub fn with_signals_chan_and_yield_now_fn( signals: (Sender<Signal>, Receiver<Signal>), yield_now_fn: Option<YieldNowFn>, ) -> Self

Constructs a new empty machine with the given signals communication channel and yielding function.

Source

pub fn add_clearable(&mut self, clearable: Box<dyn Clearable>)

Registers the given clearable.

In the common case, functions and commands hold a reference to the out-of-machine state they interact with. This state is invisible from here, but we may need to have access to it to reset it as part of the clear operation. In those cases, such state must be registered via this hook.

Source

pub fn add_callable(&mut self, callable: Rc<dyn Callable>)

Registers the given builtin callable, which must not yet be registered.

Source

pub fn get_signals_tx(&self) -> Sender<Signal>

Obtains a channel via which to send signals to the machine during execution.

Source

pub fn clear(&mut self)

Resets the state of the machine by clearing all variable.

Source

pub fn last_error(&self) -> Option<&str>

Returns the last execution error.

Source

pub fn get_data(&self) -> &[Option<Value>]

Obtains immutable access to the data values available during the current execution.

Source

pub fn get_symbols(&self) -> &Symbols

Obtains immutable access to the state of the symbols.

Source

pub fn get_mut_symbols(&mut self) -> &mut Symbols

Obtains mutable access to the state of the symbols.

Source

pub fn get_var_as_bool(&self, name: &str) -> Result<bool>

Retrieves the variable name as a boolean. Fails if it is some other type or if it’s not defined.

Source

pub fn get_var_as_int(&self, name: &str) -> Result<i32>

Retrieves the variable name as an integer. Fails if it is some other type or if it’s not defined.

Source

pub fn get_var_as_string(&self, name: &str) -> Result<&str>

Retrieves the variable name as a string. Fails if it is some other type or if it’s not defined.

Source

pub fn drain_signals(&mut self)

Consumes any pending signals so that they don’t interfere with an upcoming execution.

Source

pub async fn exec(&mut self, input: &mut dyn Read) -> Result<StopReason>

Executes a program extracted from the input readable.

Note that this does not consume self. As a result, it is possible to execute multiple different programs on the same machine, all sharing state.

Trait Implementations§

Source§

impl Default for Machine

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Machine

§

impl !RefUnwindSafe for Machine

§

impl !Send for Machine

§

impl !Sync for Machine

§

impl !Unpin for Machine

§

impl !UnwindSafe for Machine

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.