Skip to main content

Runtime

Struct Runtime 

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

The runtime environment for executing Patchwork code.

Holds variable bindings and execution context like the working directory.

Implementations§

Source§

impl Runtime

Source

pub fn new(working_dir: PathBuf) -> Self

Create a new runtime with the given working directory.

Source

pub fn with_print_sink(working_dir: PathBuf, print_sink: PrintSink) -> Self

Create a new runtime with a print sink for output redirection.

Source

pub fn set_print_sink(&mut self, sink: PrintSink)

Set the print sink for output redirection.

Source

pub fn print(&self, message: String) -> Result<(), String>

Send a print message to the sink, or stdout if no sink is configured.

Returns Ok(()) on success, or Err if the channel is disconnected.

Source

pub fn working_dir(&self) -> &PathBuf

Get the current working directory.

Source

pub fn set_working_dir(&mut self, dir: PathBuf)

Set the current working directory.

Source

pub fn push_scope(&mut self)

Push a new scope onto the scope stack (entering a block).

Source

pub fn pop_scope(&mut self)

Pop the current scope from the stack (leaving a block).

Source

pub fn define_var(&mut self, name: &str, value: Value) -> Result<(), String>

Define a new variable in the current scope.

Returns an error if the variable already exists in the current scope.

Source

pub fn get_var(&self, name: &str) -> Option<&Value>

Get the value of a variable, searching from innermost to outermost scope.

Source

pub fn set_var(&mut self, name: &str, value: Value) -> Result<(), String>

Set the value of an existing variable.

Searches from innermost to outermost scope for the variable. Returns an error if the variable doesn’t exist.

Trait Implementations§

Source§

impl Debug for Runtime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Runtime

Source§

fn default() -> Self

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

Auto Trait Implementations§

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.