pub struct Rant { /* private fields */ }
Expand description
A Rant execution context.
Implementations
sourceimpl Rant
impl Rant
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Rant context with the default seed (0) and loads the standard library.
sourcepub fn with_seed(seed: u64) -> Self
pub fn with_seed(seed: u64) -> Self
Creates a new Rant context with the specified seed and loads the standard library.
sourcepub fn with_random_seed() -> Self
pub fn with_random_seed() -> Self
Creates a new Rant context with a seed generated by a thread-local PRNG and loads the standard library.
sourcepub fn with_options(options: RantOptions) -> Self
pub fn with_options(options: RantOptions) -> Self
Creates a new Rant context with the specified options.
sourcepub fn using_module_resolver<R: ModuleResolver + 'static>(
self,
module_resolver: R
) -> Self
pub fn using_module_resolver<R: ModuleResolver + 'static>(
self,
module_resolver: R
) -> Self
Replaces the module resolver.
sourceimpl Rant
impl Rant
sourcepub fn compile<R: Reporter>(
&self,
source: &str,
reporter: &mut R
) -> Result<RantProgram, CompilerError>
pub fn compile<R: Reporter>(
&self,
source: &str,
reporter: &mut R
) -> Result<RantProgram, CompilerError>
Compiles a source string using the specified reporter.
sourcepub fn compile_named<R: Reporter>(
&self,
source: &str,
reporter: &mut R,
name: &str
) -> Result<RantProgram, CompilerError>
pub fn compile_named<R: Reporter>(
&self,
source: &str,
reporter: &mut R,
name: &str
) -> Result<RantProgram, CompilerError>
Compiles a source string using the specified reporter and source name.
sourcepub fn compile_quiet(&self, source: &str) -> Result<RantProgram, CompilerError>
pub fn compile_quiet(&self, source: &str) -> Result<RantProgram, CompilerError>
Compiles a source string without reporting problems.
Note
This method will not generate any compiler messages, even if it fails.
If you require this information, use the compile()
method instead.
sourcepub fn compile_quiet_named(
&self,
source: &str,
name: &str
) -> Result<RantProgram, CompilerError>
pub fn compile_quiet_named(
&self,
source: &str,
name: &str
) -> Result<RantProgram, CompilerError>
Compiles a source string without reporting problems and assigns it the specified name.
Note
This method will not generate any compiler messages, even if it fails.
If you require this information, use the compile()
method instead.
sourcepub fn compile_file<P: AsRef<Path>, R: Reporter>(
&self,
path: P,
reporter: &mut R
) -> Result<RantProgram, CompilerError>
pub fn compile_file<P: AsRef<Path>, R: Reporter>(
&self,
path: P,
reporter: &mut R
) -> Result<RantProgram, CompilerError>
Compiles a source file using the specified reporter.
sourcepub fn compile_file_quiet<P: AsRef<Path>>(
&self,
path: P
) -> Result<RantProgram, CompilerError>
pub fn compile_file_quiet<P: AsRef<Path>>(
&self,
path: P
) -> Result<RantProgram, CompilerError>
Compiles a source file without reporting problems.
Note
This method will not generate any compiler messages, even if it fails.
If you require this information, use the compile_file()
method instead.
sourcepub fn set_global(&mut self, key: &str, value: RantValue) -> bool
pub fn set_global(&mut self, key: &str, value: RantValue) -> bool
Sets a global variable. This will auto-define the global if it doesn’t exist.
If the global already exists and is a constant, the write will not succeed.
Returns true
if the write succeeded; otherwise, false
.
sourcepub fn set_global_const(&mut self, key: &str, value: RantValue) -> bool
pub fn set_global_const(&mut self, key: &str, value: RantValue) -> bool
Sets a global constant. This will auto-define the global if it doesn’t exist.
If the global already exists and is a constant, the write will not succeed.
Returns true
if the write succeeded; otherwise, false
.
sourcepub fn set_global_force(&mut self, key: &str, value: RantValue, is_const: bool)
pub fn set_global_force(&mut self, key: &str, value: RantValue, is_const: bool)
Sets a global’s value, forcing the write even if the existing global is a constant. This will auto-define the global if it doesn’t exist.
sourcepub fn get_global(&self, key: &str) -> Option<RantValue>
pub fn get_global(&self, key: &str) -> Option<RantValue>
Gets the value of a global variable.
sourcepub fn has_global(&self, key: &str) -> bool
pub fn has_global(&self, key: &str) -> bool
Returns true
if a global with the specified key exists.
sourcepub fn delete_global(&mut self, key: &str) -> bool
pub fn delete_global(&mut self, key: &str) -> bool
Removes the global with the specified key. Returns true
if the global existed prior to removal.
sourcepub fn global_names(&self) -> impl Iterator<Item = &str>
pub fn global_names(&self) -> impl Iterator<Item = &str>
Iterates over the names of all globals stored in the context.
sourcepub fn options(&self) -> &RantOptions
pub fn options(&self) -> &RantOptions
Gets the options used to initialize the context.
sourcepub fn reset_seed(&mut self)
pub fn reset_seed(&mut self)
Resets the RNG back to its initial state with the current seed.
sourcepub fn add_data_source(
&mut self,
data_source: impl DataSource + 'static
) -> Result<(), DataSourceRegisterError>
pub fn add_data_source(
&mut self,
data_source: impl DataSource + 'static
) -> Result<(), DataSourceRegisterError>
Registers a data source to the context, making it available to scripts.
sourcepub fn remove_data_source(&mut self, name: &str) -> Option<Box<dyn DataSource>>
pub fn remove_data_source(&mut self, name: &str) -> Option<Box<dyn DataSource>>
Removes the data source with the specified name from the context, making it no longer available to scripts.
sourcepub fn has_data_source(&self, name: &str) -> bool
pub fn has_data_source(&self, name: &str) -> bool
Returns a bool
indicating whether a data source with the specified name is present in the context.
sourcepub fn clear_data_sources(&mut self)
pub fn clear_data_sources(&mut self)
Removes all data sources from the context.
sourcepub fn data_source(&self, name: &str) -> Option<&dyn DataSource>
pub fn data_source(&self, name: &str) -> Option<&dyn DataSource>
Returns a reference to the data source associated with the specified name.
sourcepub fn iter_data_sources(
&self
) -> impl Iterator<Item = (&str, &Box<dyn DataSource + 'static>)>
pub fn iter_data_sources(
&self
) -> impl Iterator<Item = (&str, &Box<dyn DataSource + 'static>)>
Iterates over all data sources (and their names) in the context.
sourcepub fn run(&mut self, program: &RantProgram) -> RuntimeResult<RantValue>
pub fn run(&mut self, program: &RantProgram) -> RuntimeResult<RantValue>
Runs a program and returns the output value.
sourcepub fn run_with<A>(
&mut self,
program: &RantProgram,
args: A
) -> RuntimeResult<RantValue> where
A: Into<Option<HashMap<String, RantValue>>>,
pub fn run_with<A>(
&mut self,
program: &RantProgram,
args: A
) -> RuntimeResult<RantValue> where
A: Into<Option<HashMap<String, RantValue>>>,
Runs a program with the specified arguments and returns the output value.
pub fn try_load_global_module(
&mut self,
module_path: &str
) -> Result<(), ModuleLoadError>
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Rant
impl !Send for Rant
impl !Sync for Rant
impl Unpin for Rant
impl !UnwindSafe for Rant
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