Metta

Struct Metta 

Source
pub struct Metta(/* private fields */);
Expand description

A Metta object encapsulates everything needed to execute MeTTa code

Implementations§

Source§

impl Metta

Source

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

Source

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

Source

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’

Source

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.

Source

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

Source

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.

Source

pub fn display_loaded_modules(&self)

Writes a textual description of the loaded modules to stdout

Source

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

Source

pub fn environment(&self) -> &Environment

Returns a reference to the Environment used by the runner

Source

pub fn space(&self) -> &DynSpace

Returns a reference to the Space associated with the runner’s top module

Source

pub fn module_space(&self, mod_id: ModId) -> DynSpace

Returns the [DynSpace] handle associated with any loaded module’s Space

Source

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

Source

pub fn tokenizer(&self) -> &Shared<Tokenizer>

Returns a reference to the Tokenizer associated with the runner’s top module

Source

pub fn settings(&self) -> &PragmaSettings

Source

pub fn get_setting_string(&self, key: &str) -> Option<String>

Source

pub fn run(&self, parser: impl Parser) -> Result<Vec<Vec<Atom>>, String>

Source

pub fn run_in_module( &self, mod_id: ModId, parser: impl Parser, ) -> Result<Vec<Vec<Atom>>, String>

Source

pub fn evaluate_atom(&self, atom: Atom) -> Result<Vec<Atom>, String>

Trait Implementations§

Source§

impl Clone for Metta

Source§

fn clone(&self) -> Metta

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Metta

Source§

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

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

impl PartialEq for Metta

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
§

impl<T> AutoGroundedType for T
where T: 'static + PartialEq + Clone + Debug,