RunContext

Struct RunContext 

Source
pub struct RunContext<'a, 'input> { /* private fields */ }
Expand description

Runtime data that is available to Grounded Atom execution

Implementations§

Source§

impl<'input> RunContext<'_, 'input>

Source

pub fn metta(&self) -> &Metta

Returns access to the Metta runner that is hosting the context

Source

pub fn module(&self) -> &MettaMod

Returns access to the context’s current module

Source

pub fn module_mut(&mut self) -> Option<&mut MettaMod>

Returns mutable access the context’s current module, if possible

Source

pub fn push_parser(&mut self, parser: Box<dyn Parser + 'input>)

Pushes the parser as a source of operations to subsequently execute

Source

pub fn push_atoms(&mut self, atoms: &'input [Atom])

Pushes the atoms as a source of operations to subsequently execute

Source

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

Source

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

Source

pub fn get_module_by_name(&self, mod_name: &str) -> Result<ModId, String>

Locates and retrieves a loaded module based on its name

Source

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

Source

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

Source

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

Source

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

Source

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.

Source

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

Source

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

Source

pub fn import_dependency_as( &self, mod_id: ModId, name: Option<String>, ) -> Result<(), String>

Adds a loaded module as a dependency of the &self MettaMod, and adds a Tokenizer entry to access the dependent module’s Space.

Source

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_name argument exactly matches a Tokenizer entry in the source module, then that entry will be imported, and the name argument 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_name into an atom, using the Tokenizer and [Space] associated with the dependent module, and the resolved atom will be imported into the &self [Space]
  • If name is provided, then if the resolved atom not a Symbol or if the resolved atom is a symbol that doesn’t perfectly match name, a new Tokenizer entry will be created to access the atom in the &self module
Source

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§

Source§

impl Debug for RunContext<'_, '_>

Source§

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

Formats the value using the given formatter. Read more

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> 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> RefOrMove<T> for T

§

fn as_value(self) -> T

§

fn as_ref(&self) -> &T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more