Implement string functions with to_string/to_debug.
This commit is contained in:
@@ -3,9 +3,8 @@ use crate::stdlib::{
|
||||
collections::BTreeMap,
|
||||
io::Error as IoError,
|
||||
path::{Path, PathBuf},
|
||||
string::String,
|
||||
};
|
||||
use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared};
|
||||
use crate::{Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, Shared};
|
||||
|
||||
pub const RHAI_SCRIPT_EXTENSION: &str = "rhai";
|
||||
|
||||
@@ -42,7 +41,7 @@ pub const RHAI_SCRIPT_EXTENSION: &str = "rhai";
|
||||
#[derive(Debug)]
|
||||
pub struct FileModuleResolver {
|
||||
base_path: Option<PathBuf>,
|
||||
extension: String,
|
||||
extension: Identifier,
|
||||
cache_enabled: bool,
|
||||
|
||||
#[cfg(not(feature = "sync"))]
|
||||
@@ -118,7 +117,7 @@ impl FileModuleResolver {
|
||||
/// engine.set_module_resolver(resolver);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
pub fn new_with_extension(extension: impl Into<String>) -> Self {
|
||||
pub fn new_with_extension(extension: impl Into<Identifier>) -> Self {
|
||||
Self {
|
||||
base_path: None,
|
||||
extension: extension.into(),
|
||||
@@ -145,7 +144,7 @@ impl FileModuleResolver {
|
||||
#[inline(always)]
|
||||
pub fn new_with_path_and_extension(
|
||||
path: impl Into<PathBuf>,
|
||||
extension: impl Into<String>,
|
||||
extension: impl Into<Identifier>,
|
||||
) -> Self {
|
||||
Self {
|
||||
base_path: Some(path.into()),
|
||||
@@ -175,7 +174,7 @@ impl FileModuleResolver {
|
||||
|
||||
/// Set the script file extension.
|
||||
#[inline(always)]
|
||||
pub fn set_extension(&mut self, extension: impl Into<String>) -> &mut Self {
|
||||
pub fn set_extension(&mut self, extension: impl Into<Identifier>) -> &mut Self {
|
||||
self.extension = extension.into();
|
||||
self
|
||||
}
|
||||
@@ -256,7 +255,7 @@ impl FileModuleResolver {
|
||||
file_path = path.into();
|
||||
}
|
||||
|
||||
file_path.set_extension(&self.extension); // Force extension
|
||||
file_path.set_extension(self.extension.as_str()); // Force extension
|
||||
file_path
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
use crate::stdlib::{boxed::Box, collections::BTreeMap, ops::AddAssign, string::String};
|
||||
use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared};
|
||||
use crate::{Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, Shared};
|
||||
|
||||
/// A static [module][Module] resolution service that serves [modules][Module] added into it.
|
||||
///
|
||||
@@ -19,7 +19,7 @@ use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared};
|
||||
/// engine.set_module_resolver(resolver);
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct StaticModuleResolver(BTreeMap<String, Shared<Module>>);
|
||||
pub struct StaticModuleResolver(BTreeMap<Identifier, Shared<Module>>);
|
||||
|
||||
impl StaticModuleResolver {
|
||||
/// Create a new [`StaticModuleResolver`].
|
||||
@@ -44,7 +44,7 @@ impl StaticModuleResolver {
|
||||
}
|
||||
/// Add a [module][Module] keyed by its path.
|
||||
#[inline(always)]
|
||||
pub fn insert(&mut self, path: impl Into<String>, mut module: Module) {
|
||||
pub fn insert(&mut self, path: impl Into<Identifier>, mut module: Module) {
|
||||
module.build_index();
|
||||
self.0.insert(path.into(), module.into());
|
||||
}
|
||||
@@ -70,13 +70,13 @@ impl StaticModuleResolver {
|
||||
}
|
||||
/// Get a mutable iterator of all the modules.
|
||||
#[inline(always)]
|
||||
pub fn into_iter(self) -> impl Iterator<Item = (String, Shared<Module>)> {
|
||||
pub fn into_iter(self) -> impl Iterator<Item = (Identifier, Shared<Module>)> {
|
||||
self.0.into_iter()
|
||||
}
|
||||
/// Get an iterator of all the [module][Module] paths.
|
||||
#[inline(always)]
|
||||
pub fn paths(&self) -> impl Iterator<Item = &str> {
|
||||
self.0.keys().map(String::as_str)
|
||||
self.0.keys().map(|s| s.as_str())
|
||||
}
|
||||
/// Get an iterator of all the [modules][Module].
|
||||
#[inline(always)]
|
||||
|
Reference in New Issue
Block a user