Struct rhai::module_resolvers::StaticModuleResolver
source · pub struct StaticModuleResolver(/* private fields */);
Expand description
A static module resolution service that serves modules added into it.
§Example
use rhai::{Engine, Module};
use rhai::module_resolvers::StaticModuleResolver;
let mut resolver = StaticModuleResolver::new();
let module = Module::new();
resolver.insert("hello", module);
let mut engine = Engine::new();
engine.set_module_resolver(resolver);
Implementations§
source§impl StaticModuleResolver
impl StaticModuleResolver
sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new StaticModuleResolver
.
§Example
use rhai::{Engine, Module};
use rhai::module_resolvers::StaticModuleResolver;
let mut resolver = StaticModuleResolver::new();
let module = Module::new();
resolver.insert("hello", module);
let mut engine = Engine::new();
engine.set_module_resolver(resolver);
sourcepub fn insert(&mut self, path: impl Into<Identifier>, module: Module)
pub fn insert(&mut self, path: impl Into<Identifier>, module: Module)
Add a module keyed by its path.
sourcepub fn contains_path(&self, path: &str) -> bool
pub fn contains_path(&self, path: &str) -> bool
Does the path exist?
sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &Shared<Module>)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &Shared<Module>)>
Get an iterator of all the modules.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)>
Get a mutable iterator of all the modules.
sourcepub fn values(&self) -> impl Iterator<Item = &Shared<Module>>
pub fn values(&self) -> impl Iterator<Item = &Shared<Module>>
Get an iterator of all the modules.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if this StaticModuleResolver
contains no module resolvers.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the number of modules in this StaticModuleResolver
.
sourcepub fn merge(&mut self, other: Self) -> &mut Self
pub fn merge(&mut self, other: Self) -> &mut Self
Merge another StaticModuleResolver
into this.
The other StaticModuleResolver
is consumed.
Existing modules of the same path name are overwritten.
Trait Implementations§
source§impl AddAssign for StaticModuleResolver
impl AddAssign for StaticModuleResolver
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moresource§impl Clone for StaticModuleResolver
impl Clone for StaticModuleResolver
source§fn clone(&self) -> StaticModuleResolver
fn clone(&self) -> StaticModuleResolver
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for StaticModuleResolver
impl Debug for StaticModuleResolver
source§impl Default for StaticModuleResolver
impl Default for StaticModuleResolver
source§fn default() -> StaticModuleResolver
fn default() -> StaticModuleResolver
Returns the “default value” for a type. Read more
source§impl<'a> IntoIterator for &'a StaticModuleResolver
impl<'a> IntoIterator for &'a StaticModuleResolver
§type Item = (&'a SmartString<LazyCompact>, &'a Rc<Module>)
type Item = (&'a SmartString<LazyCompact>, &'a Rc<Module>)
The type of the elements being iterated over.
§type IntoIter = Iter<'a, SmartString<LazyCompact>, Rc<Module>>
type IntoIter = Iter<'a, SmartString<LazyCompact>, Rc<Module>>
Which kind of iterator are we turning this into?
source§impl IntoIterator for StaticModuleResolver
impl IntoIterator for StaticModuleResolver
§type Item = (SmartString<LazyCompact>, Rc<Module>)
type Item = (SmartString<LazyCompact>, Rc<Module>)
The type of the elements being iterated over.
§type IntoIter = IntoIter<SmartString<LazyCompact>, Rc<Module>>
type IntoIter = IntoIter<SmartString<LazyCompact>, Rc<Module>>
Which kind of iterator are we turning this into?
source§impl ModuleResolver for StaticModuleResolver
impl ModuleResolver for StaticModuleResolver
source§fn resolve(
&self,
_: &Engine,
_: Option<&str>,
path: &str,
pos: Position,
) -> Result<Shared<Module>, Box<EvalAltResult>>
fn resolve( &self, _: &Engine, _: Option<&str>, path: &str, pos: Position, ) -> Result<Shared<Module>, Box<EvalAltResult>>
Resolve a module based on a path string.
source§fn resolve_raw(
&self,
engine: &Engine,
global: &mut GlobalRuntimeState,
scope: &mut Scope<'_>,
path: &str,
pos: Position,
) -> Result<Shared<Module>, Box<EvalAltResult>>
fn resolve_raw( &self, engine: &Engine, global: &mut GlobalRuntimeState, scope: &mut Scope<'_>, path: &str, pos: Position, ) -> Result<Shared<Module>, Box<EvalAltResult>>
Resolve a module based on a path string, given a
GlobalRuntimeState
and the current Scope
. Read moreAuto Trait Implementations§
impl Freeze for StaticModuleResolver
impl !RefUnwindSafe for StaticModuleResolver
impl !Send for StaticModuleResolver
impl !Sync for StaticModuleResolver
impl Unpin for StaticModuleResolver
impl !UnwindSafe for StaticModuleResolver
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> Variant for T
impl<T> Variant for T
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert this
Variant
trait object to &mut dyn Any
.source§fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
Convert this
Variant
trait object to Box<dyn Any>
.