Minor refactors.
This commit is contained in:
parent
82317f0dbf
commit
c727b529f5
@ -695,13 +695,13 @@ impl Engine {
|
|||||||
|
|
||||||
if root.is_empty() || !root.contains_key(sub_module) {
|
if root.is_empty() || !root.contains_key(sub_module) {
|
||||||
let mut m = Module::new();
|
let mut m = Module::new();
|
||||||
register_static_module_raw(m.get_sub_modules(), remainder, module);
|
register_static_module_raw(m.get_sub_modules_mut(), remainder, module);
|
||||||
m.build_index();
|
m.build_index();
|
||||||
root.insert(sub_module.into(), m.into());
|
root.insert(sub_module.into(), m.into());
|
||||||
} else {
|
} else {
|
||||||
let m = root.remove(sub_module).expect("contains sub-module");
|
let m = root.remove(sub_module).expect("contains sub-module");
|
||||||
let mut m = crate::func::shared_take_or_clone(m);
|
let mut m = crate::func::shared_take_or_clone(m);
|
||||||
register_static_module_raw(m.get_sub_modules(), remainder, module);
|
register_static_module_raw(m.get_sub_modules_mut(), remainder, module);
|
||||||
m.build_index();
|
m.build_index();
|
||||||
root.insert(sub_module.into(), m.into());
|
root.insert(sub_module.into(), m.into());
|
||||||
}
|
}
|
||||||
|
@ -25,32 +25,42 @@ const BUILTIN: &str = "data type was checked";
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn is_numeric(type_id: TypeId) -> bool {
|
fn is_numeric(type_id: TypeId) -> bool {
|
||||||
let result = false;
|
if type_id == TypeId::of::<INT>() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "only_i64"))]
|
#[cfg(not(feature = "only_i64"))]
|
||||||
#[cfg(not(feature = "only_i32"))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
let result = result
|
if type_id == TypeId::of::<u8>()
|
||||||
|| type_id == TypeId::of::<u8>()
|
|
||||||
|| type_id == TypeId::of::<u16>()
|
|| type_id == TypeId::of::<u16>()
|
||||||
|| type_id == TypeId::of::<u32>()
|
|| type_id == TypeId::of::<u32>()
|
||||||
|| type_id == TypeId::of::<u64>()
|
|| type_id == TypeId::of::<u64>()
|
||||||
|| type_id == TypeId::of::<i8>()
|
|| type_id == TypeId::of::<i8>()
|
||||||
|| type_id == TypeId::of::<i16>()
|
|| type_id == TypeId::of::<i16>()
|
||||||
|| type_id == TypeId::of::<i32>()
|
|| type_id == TypeId::of::<i32>()
|
||||||
|| type_id == TypeId::of::<i64>();
|
|| type_id == TypeId::of::<i64>()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "only_i64"))]
|
#[cfg(not(feature = "only_i64"))]
|
||||||
#[cfg(not(feature = "only_i32"))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
let result = result || type_id == TypeId::of::<u128>() || type_id == TypeId::of::<i128>();
|
if type_id == TypeId::of::<u128>() || type_id == TypeId::of::<i128>() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
let result = result || type_id == TypeId::of::<f32>() || type_id == TypeId::of::<f64>();
|
if type_id == TypeId::of::<f32>() || type_id == TypeId::of::<f64>() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
let result = result || type_id == TypeId::of::<rust_decimal::Decimal>();
|
if type_id == TypeId::of::<rust_decimal::Decimal>() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
result
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build in common binary operator implementations to avoid the cost of calling a registered function.
|
/// Build in common binary operator implementations to avoid the cost of calling a registered function.
|
||||||
@ -61,8 +71,6 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
|||||||
let type1 = x.type_id();
|
let type1 = x.type_id();
|
||||||
let type2 = y.type_id();
|
let type2 = y.type_id();
|
||||||
|
|
||||||
let types_pair = (type1, type2);
|
|
||||||
|
|
||||||
macro_rules! impl_op {
|
macro_rules! impl_op {
|
||||||
($xx:ident $op:tt $yy:ident) => { |_, args| {
|
($xx:ident $op:tt $yy:ident) => { |_, args| {
|
||||||
let x = &*args[0].read_lock::<$xx>().expect(BUILTIN);
|
let x = &*args[0].read_lock::<$xx>().expect(BUILTIN);
|
||||||
@ -255,7 +263,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
macro_rules! impl_float {
|
macro_rules! impl_float {
|
||||||
($x:ty, $xx:ident, $y:ty, $yy:ident) => {
|
($x:ty, $xx:ident, $y:ty, $yy:ident) => {
|
||||||
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
if (type1, type2) == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+" => Some(impl_op!(FLOAT => $xx + $yy)),
|
"+" => Some(impl_op!(FLOAT => $xx + $yy)),
|
||||||
"-" => Some(impl_op!(FLOAT => $xx - $yy)),
|
"-" => Some(impl_op!(FLOAT => $xx - $yy)),
|
||||||
@ -285,7 +293,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
|||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
macro_rules! impl_decimal {
|
macro_rules! impl_decimal {
|
||||||
($x:ty, $xx:ident, $y:ty, $yy:ident) => {
|
($x:ty, $xx:ident, $y:ty, $yy:ident) => {
|
||||||
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
if (type1, type2) == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
use crate::packages::arithmetic::decimal_functions::*;
|
use crate::packages::arithmetic::decimal_functions::*;
|
||||||
|
|
||||||
@ -335,7 +343,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
|||||||
}
|
}
|
||||||
|
|
||||||
// char op string
|
// char op string
|
||||||
if types_pair == (TypeId::of::<char>(), TypeId::of::<ImmutableString>()) {
|
if (type1, type2) == (TypeId::of::<char>(), TypeId::of::<ImmutableString>()) {
|
||||||
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
|
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
|
||||||
let x = args[0].as_char().expect(BUILTIN);
|
let x = args[0].as_char().expect(BUILTIN);
|
||||||
let y = &*args[1].read_lock::<ImmutableString>().expect(BUILTIN);
|
let y = &*args[1].read_lock::<ImmutableString>().expect(BUILTIN);
|
||||||
@ -361,7 +369,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
// string op char
|
// string op char
|
||||||
if types_pair == (TypeId::of::<ImmutableString>(), TypeId::of::<char>()) {
|
if (type1, type2) == (TypeId::of::<ImmutableString>(), TypeId::of::<char>()) {
|
||||||
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
|
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
|
||||||
let x = &*args[0].read_lock::<ImmutableString>().expect(BUILTIN);
|
let x = &*args[0].read_lock::<ImmutableString>().expect(BUILTIN);
|
||||||
let y = args[1].as_char().expect(BUILTIN);
|
let y = args[1].as_char().expect(BUILTIN);
|
||||||
@ -397,7 +405,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
// () op string
|
// () op string
|
||||||
if types_pair == (TypeId::of::<()>(), TypeId::of::<ImmutableString>()) {
|
if (type1, type2) == (TypeId::of::<()>(), TypeId::of::<ImmutableString>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+" => Some(|_, args| Ok(args[1].clone())),
|
"+" => Some(|_, args| Ok(args[1].clone())),
|
||||||
"==" | ">" | ">=" | "<" | "<=" => Some(|_, _| Ok(Dynamic::FALSE)),
|
"==" | ">" | ">=" | "<" | "<=" => Some(|_, _| Ok(Dynamic::FALSE)),
|
||||||
@ -406,7 +414,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
// string op ()
|
// string op ()
|
||||||
if types_pair == (TypeId::of::<ImmutableString>(), TypeId::of::<()>()) {
|
if (type1, type2) == (TypeId::of::<ImmutableString>(), TypeId::of::<()>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+" => Some(|_, args| Ok(args[0].clone())),
|
"+" => Some(|_, args| Ok(args[0].clone())),
|
||||||
"==" | ">" | ">=" | "<" | "<=" => Some(|_, _| Ok(Dynamic::FALSE)),
|
"==" | ">" | ">=" | "<" | "<=" => Some(|_, _| Ok(Dynamic::FALSE)),
|
||||||
@ -446,7 +454,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
|||||||
|
|
||||||
// map op string
|
// map op string
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
if types_pair == (TypeId::of::<crate::Map>(), TypeId::of::<ImmutableString>()) {
|
if (type1, type2) == (TypeId::of::<crate::Map>(), TypeId::of::<ImmutableString>()) {
|
||||||
use crate::Map;
|
use crate::Map;
|
||||||
|
|
||||||
return match op {
|
return match op {
|
||||||
@ -456,12 +464,12 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Non-compatible ranges
|
// Non-compatible ranges
|
||||||
if types_pair
|
if (type1, type2)
|
||||||
== (
|
== (
|
||||||
TypeId::of::<ExclusiveRange>(),
|
TypeId::of::<ExclusiveRange>(),
|
||||||
TypeId::of::<InclusiveRange>(),
|
TypeId::of::<InclusiveRange>(),
|
||||||
)
|
)
|
||||||
|| types_pair
|
|| (type1, type2)
|
||||||
== (
|
== (
|
||||||
TypeId::of::<InclusiveRange>(),
|
TypeId::of::<InclusiveRange>(),
|
||||||
TypeId::of::<ExclusiveRange>(),
|
TypeId::of::<ExclusiveRange>(),
|
||||||
@ -554,8 +562,6 @@ pub fn get_builtin_op_assignment_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Optio
|
|||||||
let type1 = x.type_id();
|
let type1 = x.type_id();
|
||||||
let type2 = y.type_id();
|
let type2 = y.type_id();
|
||||||
|
|
||||||
let types_pair = (type1, type2);
|
|
||||||
|
|
||||||
macro_rules! impl_op {
|
macro_rules! impl_op {
|
||||||
($x:ty = x $op:tt $yy:ident) => { |_, args| {
|
($x:ty = x $op:tt $yy:ident) => { |_, args| {
|
||||||
let x = args[0].$yy().expect(BUILTIN);
|
let x = args[0].$yy().expect(BUILTIN);
|
||||||
@ -691,7 +697,7 @@ pub fn get_builtin_op_assignment_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Optio
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
macro_rules! impl_float {
|
macro_rules! impl_float {
|
||||||
($x:ident, $xx:ident, $y:ty, $yy:ident) => {
|
($x:ident, $xx:ident, $y:ty, $yy:ident) => {
|
||||||
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
if (type1, type2) == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+=" => Some(impl_op!($x += $yy)),
|
"+=" => Some(impl_op!($x += $yy)),
|
||||||
"-=" => Some(impl_op!($x -= $yy)),
|
"-=" => Some(impl_op!($x -= $yy)),
|
||||||
@ -714,7 +720,7 @@ pub fn get_builtin_op_assignment_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Optio
|
|||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
macro_rules! impl_decimal {
|
macro_rules! impl_decimal {
|
||||||
($x:ident, $xx:ident, $y:ty, $yy:ident) => {
|
($x:ident, $xx:ident, $y:ty, $yy:ident) => {
|
||||||
if types_pair == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
if (type1, type2) == (TypeId::of::<$x>(), TypeId::of::<$y>()) {
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
use crate::packages::arithmetic::decimal_functions::*;
|
use crate::packages::arithmetic::decimal_functions::*;
|
||||||
|
|
||||||
@ -753,7 +759,7 @@ pub fn get_builtin_op_assignment_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Optio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// string op= char
|
// string op= char
|
||||||
if types_pair == (TypeId::of::<ImmutableString>(), TypeId::of::<char>()) {
|
if (type1, type2) == (TypeId::of::<ImmutableString>(), TypeId::of::<char>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+=" => Some(impl_op!(ImmutableString += as_char as char)),
|
"+=" => Some(impl_op!(ImmutableString += as_char as char)),
|
||||||
"-=" => Some(impl_op!(ImmutableString -= as_char as char)),
|
"-=" => Some(impl_op!(ImmutableString -= as_char as char)),
|
||||||
@ -761,7 +767,7 @@ pub fn get_builtin_op_assignment_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Optio
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
// char op= string
|
// char op= string
|
||||||
if types_pair == (TypeId::of::<char>(), TypeId::of::<ImmutableString>()) {
|
if (type1, type2) == (TypeId::of::<char>(), TypeId::of::<ImmutableString>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+=" => Some(|_, args| {
|
"+=" => Some(|_, args| {
|
||||||
let mut ch = args[0].as_char().expect(BUILTIN).to_string();
|
let mut ch = args[0].as_char().expect(BUILTIN).to_string();
|
||||||
@ -810,7 +816,7 @@ pub fn get_builtin_op_assignment_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Optio
|
|||||||
use crate::Blob;
|
use crate::Blob;
|
||||||
|
|
||||||
// blob op= int
|
// blob op= int
|
||||||
if types_pair == (TypeId::of::<Blob>(), TypeId::of::<INT>()) {
|
if (type1, type2) == (TypeId::of::<Blob>(), TypeId::of::<INT>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+=" => Some(|_, args| {
|
"+=" => Some(|_, args| {
|
||||||
let x = args[1].as_int().expect("`INT`");
|
let x = args[1].as_int().expect("`INT`");
|
||||||
@ -822,7 +828,7 @@ pub fn get_builtin_op_assignment_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Optio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// blob op= char
|
// blob op= char
|
||||||
if types_pair == (TypeId::of::<Blob>(), TypeId::of::<char>()) {
|
if (type1, type2) == (TypeId::of::<Blob>(), TypeId::of::<char>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+=" => Some(|_, args| {
|
"+=" => Some(|_, args| {
|
||||||
let x = args[1].as_char().expect("`char`");
|
let x = args[1].as_char().expect("`char`");
|
||||||
@ -834,7 +840,7 @@ pub fn get_builtin_op_assignment_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Optio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// blob op= string
|
// blob op= string
|
||||||
if types_pair == (TypeId::of::<Blob>(), TypeId::of::<ImmutableString>()) {
|
if (type1, type2) == (TypeId::of::<Blob>(), TypeId::of::<ImmutableString>()) {
|
||||||
return match op {
|
return match op {
|
||||||
"+=" => Some(|_, args| {
|
"+=" => Some(|_, args| {
|
||||||
let s = std::mem::take(args[1]).cast::<ImmutableString>();
|
let s = std::mem::take(args[1]).cast::<ImmutableString>();
|
||||||
|
@ -362,12 +362,12 @@ impl Engine {
|
|||||||
let parent_source = global.source.clone();
|
let parent_source = global.source.clone();
|
||||||
|
|
||||||
// Check if function access already in the cache
|
// Check if function access already in the cache
|
||||||
let mut local_entry = None;
|
let local_entry = &mut None;
|
||||||
|
|
||||||
let func = self.resolve_fn(
|
let func = self.resolve_fn(
|
||||||
global,
|
global,
|
||||||
caches,
|
caches,
|
||||||
&mut local_entry,
|
local_entry,
|
||||||
lib,
|
lib,
|
||||||
name,
|
name,
|
||||||
hash,
|
hash,
|
||||||
@ -640,14 +640,14 @@ impl Engine {
|
|||||||
|
|
||||||
// Script-defined function call?
|
// Script-defined function call?
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
let mut local_entry = None;
|
let local_entry = &mut None;
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
if let Some(FnResolutionCacheEntry { func, ref source }) = self
|
if let Some(FnResolutionCacheEntry { func, ref source }) = self
|
||||||
.resolve_fn(
|
.resolve_fn(
|
||||||
global,
|
global,
|
||||||
caches,
|
caches,
|
||||||
&mut local_entry,
|
local_entry,
|
||||||
lib,
|
lib,
|
||||||
fn_name,
|
fn_name,
|
||||||
hashes.script,
|
hashes.script,
|
||||||
|
@ -64,7 +64,7 @@ pub fn by_value<T: Variant + Clone>(data: &mut Dynamic) -> T {
|
|||||||
///
|
///
|
||||||
/// # Type Parameters
|
/// # Type Parameters
|
||||||
///
|
///
|
||||||
/// * `ARGS` - a tuple containing parameter types, with `&mut T` represented by [`Mut<T>`].
|
/// * `ARGS` - a tuple containing parameter types, with `&mut T` represented by `Mut<T>`.
|
||||||
/// * `RET` - return type of the function; if the function returns `Result`, it is the unwrapped inner value type.
|
/// * `RET` - return type of the function; if the function returns `Result`, it is the unwrapped inner value type.
|
||||||
pub trait RegisterNativeFunction<ARGS, RET, RESULT> {
|
pub trait RegisterNativeFunction<ARGS, RET, RESULT> {
|
||||||
/// Convert this function into a [`CallableFunction`].
|
/// Convert this function into a [`CallableFunction`].
|
||||||
|
@ -16,7 +16,7 @@ use crate::{
|
|||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
use std::{
|
use std::{
|
||||||
any::TypeId,
|
any::TypeId,
|
||||||
collections::{BTreeMap, BTreeSet},
|
collections::BTreeMap,
|
||||||
fmt,
|
fmt,
|
||||||
ops::{Add, AddAssign},
|
ops::{Add, AddAssign},
|
||||||
};
|
};
|
||||||
@ -213,7 +213,7 @@ impl fmt::Debug for Module {
|
|||||||
.iter()
|
.iter()
|
||||||
.flat_map(|m| m.keys())
|
.flat_map(|m| m.keys())
|
||||||
.map(SmartString::as_str)
|
.map(SmartString::as_str)
|
||||||
.collect::<BTreeSet<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
)
|
)
|
||||||
.field("vars", &self.variables)
|
.field("vars", &self.variables)
|
||||||
.field(
|
.field(
|
||||||
@ -221,7 +221,7 @@ impl fmt::Debug for Module {
|
|||||||
&self
|
&self
|
||||||
.iter_fn()
|
.iter_fn()
|
||||||
.map(|f| f.func.to_string())
|
.map(|f| f.func.to_string())
|
||||||
.collect::<BTreeSet<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
@ -710,8 +710,7 @@ impl Module {
|
|||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
comments: Box::default(),
|
comments: Box::default(),
|
||||||
func: fn_def.into(),
|
func: fn_def.into(),
|
||||||
}
|
},
|
||||||
.into(),
|
|
||||||
);
|
);
|
||||||
self.indexed = false;
|
self.indexed = false;
|
||||||
self.contains_indexed_global_functions = false;
|
self.contains_indexed_global_functions = false;
|
||||||
@ -749,7 +748,7 @@ impl Module {
|
|||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn get_sub_modules(&mut self) -> &mut BTreeMap<Identifier, Shared<Module>> {
|
pub(crate) fn get_sub_modules_mut(&mut self) -> &mut BTreeMap<Identifier, Shared<Module>> {
|
||||||
// We must assume that the user has changed the sub-modules
|
// We must assume that the user has changed the sub-modules
|
||||||
// (otherwise why take a mutable reference?)
|
// (otherwise why take a mutable reference?)
|
||||||
self.all_functions = None;
|
self.all_functions = None;
|
||||||
@ -1044,8 +1043,7 @@ impl Module {
|
|||||||
return_type: return_type_name,
|
return_type: return_type_name,
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
comments: Box::default(),
|
comments: Box::default(),
|
||||||
}
|
},
|
||||||
.into(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
self.indexed = false;
|
self.indexed = false;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use crate::eval::GlobalRuntimeState;
|
use crate::eval::GlobalRuntimeState;
|
||||||
use crate::func::{locked_read, locked_write};
|
use crate::func::{locked_read, locked_write};
|
||||||
use crate::{
|
use crate::{
|
||||||
Engine, Identifier, Module, ModuleResolver, Position, RhaiResultOf, Scope, Shared, ERR,
|
Engine, Identifier, Locked, Module, ModuleResolver, Position, RhaiResultOf, Scope, Shared, ERR,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
@ -51,11 +51,7 @@ pub struct FileModuleResolver {
|
|||||||
extension: Identifier,
|
extension: Identifier,
|
||||||
cache_enabled: bool,
|
cache_enabled: bool,
|
||||||
scope: Scope<'static>,
|
scope: Scope<'static>,
|
||||||
|
cache: Locked<BTreeMap<PathBuf, Shared<Module>>>,
|
||||||
#[cfg(not(feature = "sync"))]
|
|
||||||
cache: std::cell::RefCell<BTreeMap<PathBuf, Shared<Module>>>,
|
|
||||||
#[cfg(feature = "sync")]
|
|
||||||
cache: std::sync::RwLock<BTreeMap<PathBuf, Shared<Module>>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FileModuleResolver {
|
impl Default for FileModuleResolver {
|
||||||
|
@ -1115,12 +1115,12 @@ impl Dynamic {
|
|||||||
/// Beware that you need to pass in an [`Array`][crate::Array] type for it to be recognized as
|
/// Beware that you need to pass in an [`Array`][crate::Array] type for it to be recognized as
|
||||||
/// an [`Array`][crate::Array]. A [`Vec<T>`][Vec] does not get automatically converted to an
|
/// an [`Array`][crate::Array]. A [`Vec<T>`][Vec] does not get automatically converted to an
|
||||||
/// [`Array`][crate::Array], but will be a custom type instead (stored as a trait object). Use
|
/// [`Array`][crate::Array], but will be a custom type instead (stored as a trait object). Use
|
||||||
/// `Into<Dynamic>` to convert a [`Vec<T>`][Vec] into a [`Dynamic`] as an
|
/// [`Dynamic::from_array`] to convert a [`Vec<T>`][Vec] into a [`Dynamic`] as an
|
||||||
/// [`Array`][crate::Array] value.
|
/// [`Array`][crate::Array] value.
|
||||||
///
|
///
|
||||||
/// Similarly, passing in a [`HashMap<String, T>`][std::collections::HashMap] or
|
/// Similarly, passing in a [`HashMap<String, T>`][std::collections::HashMap] or
|
||||||
/// [`BTreeMap<String, T>`][std::collections::BTreeMap] will not get a [`Map`][crate::Map] but a
|
/// [`BTreeMap<String, T>`][std::collections::BTreeMap] will not get a [`Map`][crate::Map] but a
|
||||||
/// custom type. Again, use `Into<Dynamic>` to get a [`Dynamic`] with a [`Map`][crate::Map]
|
/// custom type. Again, use [`Dynamic::from_map`] to get a [`Dynamic`] with a [`Map`][crate::Map]
|
||||||
/// value.
|
/// value.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
@ -23,7 +23,6 @@ pub const MAX_STRING_LEN: usize = 24;
|
|||||||
/// Exported under the `internals` feature only.
|
/// Exported under the `internals` feature only.
|
||||||
///
|
///
|
||||||
/// Normal identifiers, property getters and setters are interned separately.
|
/// Normal identifiers, property getters and setters are interned separately.
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct StringsInterner<'a> {
|
pub struct StringsInterner<'a> {
|
||||||
/// Maximum number of strings interned.
|
/// Maximum number of strings interned.
|
||||||
pub capacity: usize,
|
pub capacity: usize,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user