pub struct Metta(/* private fields */);Expand description
A Metta object encapsulates everything needed to execute MeTTa code
Implementations§
Source§impl Metta
impl Metta
Sourcepub fn new(env_builder: Option<EnvBuilder>) -> Metta
pub fn new(env_builder: Option<EnvBuilder>) -> Metta
A 1-line method to create a fully initialized MeTTa runner
NOTE: pass None for env_builder to use the common environment
Sourcepub fn new_with_stdlib_loader(
loader: Option<Box<dyn ModuleLoader>>,
space: Option<DynSpace>,
env_builder: Option<EnvBuilder>,
) -> Metta
pub fn new_with_stdlib_loader( loader: Option<Box<dyn ModuleLoader>>, space: Option<DynSpace>, env_builder: Option<EnvBuilder>, ) -> Metta
Create and initialize a MeTTa runner with a custom stdlib, for example a language-specific stdlib
NOTE: The custom stdlib loader may import the corelib if desired, but it won’t be imported automatically.
NOTE: Is None is passed as the loader parameter, stdlib will be an alias to corelib
pass None for space to create a new GroundingSpace
pass None for env_builder to use the common environment
Sourcepub fn new_core(
space: Option<DynSpace>,
env_builder: Option<EnvBuilder>,
) -> Self
pub fn new_core( space: Option<DynSpace>, env_builder: Option<EnvBuilder>, ) -> Self
Returns a new core MeTTa interpreter without any loaded corelib, stdlib, or initialization
NOTE: If space is None, a GroundingSpace will be created
NOTE: If env_builder is None, the common environment will be used
NOTE: This function does not load any modules, nor run the Environment’s ‘init.metta’
Sourcepub fn load_module_direct(
&self,
loader: Box<dyn ModuleLoader>,
mod_name: &str,
) -> Result<ModId, String>
pub fn load_module_direct( &self, loader: Box<dyn ModuleLoader>, mod_name: &str, ) -> Result<ModId, String>
Loads a module into a Runner, directly from a ModuleLoader
NOTE: mod_name may be a module name path if this module is being loaded as a sub-module of
another loaded module. Relative paths may not be used with this API, however. Use
RunContext::load_module_direct if you are loading a sub-module from within a running module.
Sourcepub fn load_module_at_path<P: AsRef<Path>>(
&self,
path: P,
mod_name: Option<&str>,
) -> Result<ModId, String>
pub fn load_module_at_path<P: AsRef<Path>>( &self, path: P, mod_name: Option<&str>, ) -> Result<ModId, String>
Loads a module into a runner from a resource at the specified path
This method will try each FsModuleFormat in order until one can sucessfully load the module
NOTE: mod_name may be a module name path if the module is being loaded as a sub-module of
another loaded module. Relative paths may not be used with this API, however. Use
RunContext::load_module_at_path if you are loading a sub-module from within a running module.
Requires the pkg_mgmt feature
Sourcepub fn load_module_alias(
&self,
mod_name: &str,
mod_id: ModId,
) -> Result<ModId, String>
pub fn load_module_alias( &self, mod_name: &str, mod_id: ModId, ) -> Result<ModId, String>
Makes a public alias for a loaded module inside the runner
NOTE: mod_name may be a module name path if this alias is being loaded as a sub-module of
another loaded module. Relative paths may not be used with this API, however. Use
RunContext::load_module_alias if you are creating an alias from within a running module.
Sourcepub fn display_loaded_modules(&self)
pub fn display_loaded_modules(&self)
Writes a textual description of the loaded modules to stdout
Sourcepub fn get_module_with_descriptor(
&self,
descriptor: &ModuleDescriptor,
) -> Option<ModId>
pub fn get_module_with_descriptor( &self, descriptor: &ModuleDescriptor, ) -> Option<ModId>
Returns the ModId of a loaded module, based on its descriptor, or None if it isn’t loaded
Sourcepub fn environment(&self) -> &Environment
pub fn environment(&self) -> &Environment
Returns a reference to the Environment used by the runner
Sourcepub fn space(&self) -> &DynSpace
pub fn space(&self) -> &DynSpace
Returns a reference to the Space associated with the runner’s top module
Sourcepub fn module_space(&self, mod_id: ModId) -> DynSpace
pub fn module_space(&self, mod_id: ModId) -> DynSpace
Returns the [DynSpace] handle associated with any loaded module’s Space
Sourcepub fn get_module_resource(
&self,
mod_id: ModId,
res_key: ResourceKey<'_>,
) -> Result<Resource, String>
pub fn get_module_resource( &self, mod_id: ModId, res_key: ResourceKey<'_>, ) -> Result<Resource, String>
Returns a buffer containing the specified resource, if it is available from a loaded module
Sourcepub fn tokenizer(&self) -> &Shared<Tokenizer>
pub fn tokenizer(&self) -> &Shared<Tokenizer>
Returns a reference to the Tokenizer associated with the runner’s top module
pub fn settings(&self) -> &PragmaSettings
pub fn get_setting_string(&self, key: &str) -> Option<String>
pub fn run(&self, parser: impl Parser) -> Result<Vec<Vec<Atom>>, String>
pub fn run_in_module( &self, mod_id: ModId, parser: impl Parser, ) -> Result<Vec<Vec<Atom>>, String>
pub fn evaluate_atom(&self, atom: Atom) -> Result<Vec<Atom>, String>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Metta
impl !RefUnwindSafe for Metta
impl !Send for Metta
impl !Sync for Metta
impl Unpin for Metta
impl !UnwindSafe for Metta
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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