Clean up types.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
Engine, Module, ModuleResolver, Position, RhaiResultOf, Shared, StaticVec, ERR,
|
||||
Engine, ModuleResolver, Position, RhaiResultOf, SharedModule, StaticVec, ERR,
|
||||
STATIC_VEC_INLINE_SIZE,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
@@ -138,7 +138,7 @@ impl ModuleResolver for ModuleResolversCollection {
|
||||
source_path: Option<&str>,
|
||||
path: &str,
|
||||
pos: Position,
|
||||
) -> RhaiResultOf<Shared<Module>> {
|
||||
) -> RhaiResultOf<SharedModule> {
|
||||
for resolver in &self.0 {
|
||||
match resolver.resolve(engine, source_path, path, pos) {
|
||||
Ok(module) => return Ok(module),
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use crate::{Engine, Module, ModuleResolver, Position, RhaiResultOf, Shared, ERR};
|
||||
use crate::{Engine, ModuleResolver, Position, RhaiResultOf, SharedModule, ERR};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
||||
@@ -45,7 +45,7 @@ impl ModuleResolver for DummyModuleResolver {
|
||||
_: Option<&str>,
|
||||
path: &str,
|
||||
pos: Position,
|
||||
) -> RhaiResultOf<Shared<Module>> {
|
||||
) -> RhaiResultOf<SharedModule> {
|
||||
Err(ERR::ErrorModuleNotFound(path.into(), pos).into())
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,8 @@
|
||||
use crate::eval::GlobalRuntimeState;
|
||||
use crate::func::{locked_read, locked_write};
|
||||
use crate::{
|
||||
Engine, Identifier, Locked, Module, ModuleResolver, Position, RhaiResultOf, Scope, Shared, ERR,
|
||||
Engine, Identifier, Locked, Module, ModuleResolver, Position, RhaiResultOf, Scope, Shared,
|
||||
SharedModule, ERR,
|
||||
};
|
||||
|
||||
use std::{
|
||||
@@ -51,7 +52,7 @@ pub struct FileModuleResolver {
|
||||
extension: Identifier,
|
||||
cache_enabled: bool,
|
||||
scope: Scope<'static>,
|
||||
cache: Locked<BTreeMap<PathBuf, Shared<Module>>>,
|
||||
cache: Locked<BTreeMap<PathBuf, SharedModule>>,
|
||||
}
|
||||
|
||||
impl Default for FileModuleResolver {
|
||||
@@ -258,7 +259,7 @@ impl FileModuleResolver {
|
||||
/// The next time this path is resolved, the script file will be loaded once again.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn clear_cache_for_path(&mut self, path: impl AsRef<Path>) -> Option<Shared<Module>> {
|
||||
pub fn clear_cache_for_path(&mut self, path: impl AsRef<Path>) -> Option<SharedModule> {
|
||||
locked_write(&self.cache)
|
||||
.remove_entry(path.as_ref())
|
||||
.map(|(.., v)| v)
|
||||
@@ -293,7 +294,7 @@ impl FileModuleResolver {
|
||||
source: Option<&str>,
|
||||
path: &str,
|
||||
pos: Position,
|
||||
) -> Result<Shared<Module>, Box<crate::EvalAltResult>> {
|
||||
) -> Result<SharedModule, Box<crate::EvalAltResult>> {
|
||||
// Load relative paths from source if there is no base path specified
|
||||
let source_path = global
|
||||
.as_ref()
|
||||
@@ -344,7 +345,7 @@ impl ModuleResolver for FileModuleResolver {
|
||||
global: &mut GlobalRuntimeState,
|
||||
path: &str,
|
||||
pos: Position,
|
||||
) -> RhaiResultOf<Shared<Module>> {
|
||||
) -> RhaiResultOf<SharedModule> {
|
||||
self.impl_resolve(engine, Some(global), None, path, pos)
|
||||
}
|
||||
|
||||
@@ -355,7 +356,7 @@ impl ModuleResolver for FileModuleResolver {
|
||||
source: Option<&str>,
|
||||
path: &str,
|
||||
pos: Position,
|
||||
) -> RhaiResultOf<Shared<Module>> {
|
||||
) -> RhaiResultOf<SharedModule> {
|
||||
self.impl_resolve(engine, None, source, path, pos)
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use crate::eval::GlobalRuntimeState;
|
||||
use crate::func::SendSync;
|
||||
use crate::{Engine, Module, Position, RhaiResultOf, Shared, AST};
|
||||
use crate::{Engine, Position, RhaiResultOf, SharedModule, AST};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
||||
@@ -25,7 +25,7 @@ pub trait ModuleResolver: SendSync {
|
||||
source: Option<&str>,
|
||||
path: &str,
|
||||
pos: Position,
|
||||
) -> RhaiResultOf<Shared<Module>>;
|
||||
) -> RhaiResultOf<SharedModule>;
|
||||
|
||||
/// Resolve a module based on a path string, given a [`GlobalRuntimeState`].
|
||||
///
|
||||
@@ -38,7 +38,7 @@ pub trait ModuleResolver: SendSync {
|
||||
global: &mut GlobalRuntimeState,
|
||||
path: &str,
|
||||
pos: Position,
|
||||
) -> RhaiResultOf<Shared<Module>> {
|
||||
) -> RhaiResultOf<SharedModule> {
|
||||
self.resolve(engine, global.source(), path, pos)
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
use crate::{
|
||||
Engine, Identifier, Module, ModuleResolver, Position, RhaiResultOf, Shared, SmartString, ERR,
|
||||
Engine, Identifier, Module, ModuleResolver, Position, RhaiResultOf, SharedModule, SmartString,
|
||||
ERR,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@@ -27,7 +28,7 @@ use std::{
|
||||
/// engine.set_module_resolver(resolver);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct StaticModuleResolver(BTreeMap<Identifier, Shared<Module>>);
|
||||
pub struct StaticModuleResolver(BTreeMap<Identifier, SharedModule>);
|
||||
|
||||
impl StaticModuleResolver {
|
||||
/// Create a new [`StaticModuleResolver`].
|
||||
@@ -65,7 +66,7 @@ impl StaticModuleResolver {
|
||||
}
|
||||
/// Remove a [module][Module] given its path.
|
||||
#[inline(always)]
|
||||
pub fn remove(&mut self, path: &str) -> Option<Shared<Module>> {
|
||||
pub fn remove(&mut self, path: &str) -> Option<SharedModule> {
|
||||
self.0.remove(path)
|
||||
}
|
||||
/// Does the path exist?
|
||||
@@ -80,12 +81,12 @@ impl StaticModuleResolver {
|
||||
}
|
||||
/// Get an iterator of all the [modules][Module].
|
||||
#[inline]
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&str, &Shared<Module>)> {
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&str, &SharedModule)> {
|
||||
self.0.iter().map(|(k, v)| (k.as_str(), v))
|
||||
}
|
||||
/// Get a mutable iterator of all the [modules][Module].
|
||||
#[inline]
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut Shared<Module>)> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut SharedModule)> {
|
||||
self.0.iter_mut().map(|(k, v)| (k.as_str(), v))
|
||||
}
|
||||
/// Get an iterator of all the [module][Module] paths.
|
||||
@@ -95,7 +96,7 @@ impl StaticModuleResolver {
|
||||
}
|
||||
/// Get an iterator of all the [modules][Module].
|
||||
#[inline(always)]
|
||||
pub fn values(&self) -> impl Iterator<Item = &Shared<Module>> {
|
||||
pub fn values(&self) -> impl Iterator<Item = &SharedModule> {
|
||||
self.0.values()
|
||||
}
|
||||
/// Remove all [modules][Module].
|
||||
@@ -130,8 +131,8 @@ impl StaticModuleResolver {
|
||||
}
|
||||
|
||||
impl IntoIterator for StaticModuleResolver {
|
||||
type Item = (Identifier, Shared<Module>);
|
||||
type IntoIter = IntoIter<SmartString, Shared<Module>>;
|
||||
type Item = (Identifier, SharedModule);
|
||||
type IntoIter = IntoIter<SmartString, SharedModule>;
|
||||
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
@@ -141,8 +142,8 @@ impl IntoIterator for StaticModuleResolver {
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a StaticModuleResolver {
|
||||
type Item = (&'a Identifier, &'a Shared<Module>);
|
||||
type IntoIter = Iter<'a, SmartString, Shared<Module>>;
|
||||
type Item = (&'a Identifier, &'a SharedModule);
|
||||
type IntoIter = Iter<'a, SmartString, SharedModule>;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
@@ -158,7 +159,7 @@ impl ModuleResolver for StaticModuleResolver {
|
||||
_: Option<&str>,
|
||||
path: &str,
|
||||
pos: Position,
|
||||
) -> RhaiResultOf<Shared<Module>> {
|
||||
) -> RhaiResultOf<SharedModule> {
|
||||
self.0
|
||||
.get(path)
|
||||
.cloned()
|
||||
|
Reference in New Issue
Block a user