pub struct RunContext<'a, 'input> { /* private fields */ }Expand description
Runtime data that is available to Grounded Atom execution
Implementations§
Source§impl<'input> RunContext<'_, 'input>
impl<'input> RunContext<'_, 'input>
Sourcepub fn module_mut(&mut self) -> Option<&mut MettaMod>
pub fn module_mut(&mut self) -> Option<&mut MettaMod>
Returns mutable access the context’s current module, if possible
Sourcepub fn push_parser(&mut self, parser: Box<dyn Parser + 'input>)
pub fn push_parser(&mut self, parser: Box<dyn Parser + 'input>)
Pushes the parser as a source of operations to subsequently execute
Sourcepub fn push_atoms(&mut self, atoms: &'input [Atom])
pub fn push_atoms(&mut self, atoms: &'input [Atom])
Pushes the atoms as a source of operations to subsequently execute
Sourcepub fn push_func<F: FnOnce(&mut RunContext<'_, '_>) -> Result<(), String> + 'input>(
&mut self,
f: F,
)
pub fn push_func<F: FnOnce(&mut RunContext<'_, '_>) -> Result<(), String> + 'input>( &mut self, f: F, )
Pushes an executable function as an operation to be executed
Sourcepub fn run_inline<F: FnOnce(&mut RunContext<'_, '_>) -> Result<(), String>>(
&mut self,
f: F,
) -> Result<Vec<Vec<Atom>>, String>
pub fn run_inline<F: FnOnce(&mut RunContext<'_, '_>) -> Result<(), String>>( &mut self, f: F, ) -> Result<Vec<Vec<Atom>>, String>
Creates a child RunContext within the current context, for immediate inline execution
Sourcepub fn get_module_by_name(&self, mod_name: &str) -> Result<ModId, String>
pub fn get_module_by_name(&self, mod_name: &str) -> Result<ModId, String>
Locates and retrieves a loaded module based on its name
Sourcepub fn normalize_module_name(&self, mod_name: &str) -> Result<String, String>
pub fn normalize_module_name(&self, mod_name: &str) -> Result<String, String>
Normalize a module name into a canonical name-path form, and expanding a relative module-path
Sourcepub fn load_module_direct(
&mut self,
loader: Box<dyn ModuleLoader>,
mod_name: &str,
) -> Result<ModId, String>
pub fn load_module_direct( &mut self, loader: Box<dyn ModuleLoader>, mod_name: &str, ) -> Result<ModId, String>
Initiates the loading of a module from a runner thread. Useful for loading sub-modules
Sourcepub fn load_module_at_path<P: AsRef<Path>>(
&mut self,
path: P,
mod_name: Option<&str>,
) -> Result<ModId, String>
pub fn load_module_at_path<P: AsRef<Path>>( &mut self, path: P, mod_name: Option<&str>, ) -> Result<ModId, String>
A version of Metta::load_module_at_path Useful for loading sub-modules
Sourcepub fn load_module_alias(
&mut self,
mod_name: &str,
mod_id: ModId,
) -> Result<ModId, String>
pub fn load_module_alias( &mut self, mod_name: &str, mod_id: ModId, ) -> Result<ModId, String>
A version of Metta::load_module_alias Useful for defining sub-module aliases
Sourcepub fn init_self_module(
&mut self,
space: DynSpace,
resource_dir: Option<PathBuf>,
)
pub fn init_self_module( &mut self, space: DynSpace, resource_dir: Option<PathBuf>, )
Initializes the context’s module. Used in the implementation of a module loader function
Prior to calling this function, any attempt to access the active module in the RunContext will lead to a panic.
Sourcepub fn load_module(&mut self, mod_name: &str) -> Result<ModId, String>
pub fn load_module(&mut self, mod_name: &str) -> Result<ModId, String>
Resolves a dependency module from a name, according to the PkgInfo of the current module, and loads it into the runner, if it’s not already loaded
Sourcepub fn load_resource_from_module(
&mut self,
mod_name: &str,
res_key: ResourceKey<'_>,
) -> Result<Resource, String>
pub fn load_resource_from_module( &mut self, mod_name: &str, res_key: ResourceKey<'_>, ) -> Result<Resource, String>
Resolves a dependency module from a name, according to the PkgInfo of the current module, and loads the specified resource from the module, without loading the module itself
NOTE: Although this method won’t load the module itself, it will load parent modules if necessary
Sourcepub fn import_dependency_as(
&self,
mod_id: ModId,
name: Option<String>,
) -> Result<(), String>
pub fn import_dependency_as( &self, mod_id: ModId, name: Option<String>, ) -> Result<(), String>
Sourcepub fn import_item_from_dependency_as(
&self,
from_name: &str,
mod_id: ModId,
name: Option<&str>,
) -> Result<(), String>
pub fn import_item_from_dependency_as( &self, from_name: &str, mod_id: ModId, name: Option<&str>, ) -> Result<(), String>
Adds a specific atom and/or Tokenizer entry from a dependency module to the &self module
Behavior:
- If the
from_nameargument exactly matches a Tokenizer entry in the source module, then that entry will be imported, and thenameargument will be ignored. In this case no atom is imported. - If an exact Tokenizer entry was not found, this method will attempt to resolve
from_nameinto an atom, using the Tokenizer and [Space] associated with the dependent module, and the resolved atom will be imported into the&self[Space] - If
nameis provided, then if the resolved atom not a Symbol or if the resolved atom is a symbol that doesn’t perfectly matchname, a new Tokenizer entry will be created to access the atom in the &self module
Sourcepub fn import_all_from_dependency(&self, mod_id: ModId) -> Result<(), String>
pub fn import_all_from_dependency(&self, mod_id: ModId) -> Result<(), String>
Effectively adds all atoms in a dependency module to the &self module, by adding the dependency module’s space as an atom inside the &self module
WARNING: Module import behavior is still WIP, specifically around “import *” behavior, and especially around transitive imports
Trait Implementations§
Auto Trait Implementations§
impl<'a, 'input> Freeze for RunContext<'a, 'input>
impl<'a, 'input> !RefUnwindSafe for RunContext<'a, 'input>
impl<'a, 'input> !Send for RunContext<'a, 'input>
impl<'a, 'input> !Sync for RunContext<'a, 'input>
impl<'a, 'input> Unpin for RunContext<'a, 'input>
impl<'a, 'input> !UnwindSafe for RunContext<'a, 'input>
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request