Fix builds.
This commit is contained in:
parent
83589be58e
commit
a9b6e8b98c
@ -9,7 +9,7 @@ use crate::{Engine, Module, Scope, INT};
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
use std::{any::type_name, borrow::Cow, cmp::Ordering, fmt, fmt::Write};
|
||||
use std::{any::type_name, borrow::Cow, cmp::Ordering, fmt};
|
||||
|
||||
impl Engine {
|
||||
/// _(metadata, internals)_ Return [`Definitions`] that can be used to generate definition files
|
||||
@ -186,6 +186,8 @@ impl Definitions<'_> {
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
{
|
||||
use std::fmt::Write;
|
||||
|
||||
for (module_name, module_def) in self.modules_impl(&config) {
|
||||
write!(
|
||||
&mut def_file,
|
||||
@ -382,6 +384,7 @@ impl Definitions<'_> {
|
||||
|
||||
impl Module {
|
||||
/// Return definitions for all items inside the [`Module`].
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
fn definition(&self, def: &Definitions) -> String {
|
||||
let mut s = String::new();
|
||||
self.write_definition(&mut s, def).unwrap();
|
||||
|
@ -213,6 +213,7 @@ impl AST {
|
||||
#[cfg(feature = "metadata")]
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn doc_mut(&mut self) -> &mut crate::SmartString {
|
||||
&mut self.doc
|
||||
}
|
||||
|
@ -14,11 +14,7 @@ use crate::{
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
fmt,
|
||||
num::NonZeroU8,
|
||||
};
|
||||
use std::{collections::BTreeSet, fmt, num::NonZeroU8};
|
||||
|
||||
pub type Precedence = NonZeroU8;
|
||||
|
||||
@ -99,7 +95,7 @@ pub struct Engine {
|
||||
pub(crate) global_modules: StaticVec<Shared<Module>>,
|
||||
/// A collection of all sub-modules directly loaded into the Engine.
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
pub(crate) global_sub_modules: BTreeMap<Identifier, Shared<Module>>,
|
||||
pub(crate) global_sub_modules: std::collections::BTreeMap<Identifier, Shared<Module>>,
|
||||
|
||||
/// A module resolution service.
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
@ -112,10 +108,11 @@ pub struct Engine {
|
||||
pub(crate) disabled_symbols: BTreeSet<Identifier>,
|
||||
/// A map containing custom keywords and precedence to recognize.
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
pub(crate) custom_keywords: BTreeMap<Identifier, Option<Precedence>>,
|
||||
pub(crate) custom_keywords: std::collections::BTreeMap<Identifier, Option<Precedence>>,
|
||||
/// Custom syntax.
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
pub(crate) custom_syntax: BTreeMap<Identifier, crate::api::custom_syntax::CustomSyntax>,
|
||||
pub(crate) custom_syntax:
|
||||
std::collections::BTreeMap<Identifier, crate::api::custom_syntax::CustomSyntax>,
|
||||
/// Callback closure for filtering variable definition.
|
||||
pub(crate) def_var_filter: Option<Box<OnDefVarCallback>>,
|
||||
/// Callback closure for resolving variable access.
|
||||
@ -265,7 +262,7 @@ impl Engine {
|
||||
global_modules: StaticVec::new_const(),
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
global_sub_modules: BTreeMap::new(),
|
||||
global_sub_modules: std::collections::BTreeMap::new(),
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
module_resolver: Box::new(crate::module::resolvers::DummyModuleResolver::new()),
|
||||
@ -273,9 +270,9 @@ impl Engine {
|
||||
interned_strings: StringsInterner::new().into(),
|
||||
disabled_symbols: BTreeSet::new(),
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
custom_keywords: BTreeMap::new(),
|
||||
custom_keywords: std::collections::BTreeMap::new(),
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
custom_syntax: BTreeMap::new(),
|
||||
custom_syntax: std::collections::BTreeMap::new(),
|
||||
|
||||
def_var_filter: None,
|
||||
resolve_var: None,
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Global runtime state.
|
||||
|
||||
use crate::{Dynamic, Engine, Identifier, ImmutableString};
|
||||
use crate::{Dynamic, Engine, Identifier};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
use std::{fmt, marker::PhantomData};
|
||||
@ -9,7 +9,7 @@ use std::{fmt, marker::PhantomData};
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub type GlobalConstants =
|
||||
crate::Shared<crate::Locked<std::collections::BTreeMap<ImmutableString, Dynamic>>>;
|
||||
crate::Shared<crate::Locked<std::collections::BTreeMap<crate::ImmutableString, Dynamic>>>;
|
||||
|
||||
/// _(internals)_ Global runtime states.
|
||||
/// Exported under the `internals` feature only.
|
||||
@ -25,7 +25,7 @@ pub type GlobalConstants =
|
||||
pub struct GlobalRuntimeState<'a> {
|
||||
/// Stack of module names.
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
keys: crate::StaticVec<ImmutableString>,
|
||||
keys: crate::StaticVec<crate::ImmutableString>,
|
||||
/// Stack of imported [modules][crate::Module].
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
modules: crate::StaticVec<crate::Shared<crate::Module>>,
|
||||
@ -169,7 +169,7 @@ impl GlobalRuntimeState<'_> {
|
||||
#[inline(always)]
|
||||
pub fn push_import(
|
||||
&mut self,
|
||||
name: impl Into<ImmutableString>,
|
||||
name: impl Into<crate::ImmutableString>,
|
||||
module: impl Into<crate::Shared<crate::Module>>,
|
||||
) {
|
||||
self.keys.push(name.into());
|
||||
@ -205,7 +205,7 @@ impl GlobalRuntimeState<'_> {
|
||||
#[inline]
|
||||
pub(crate) fn iter_imports_raw(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (&ImmutableString, &crate::Shared<crate::Module>)> {
|
||||
) -> impl Iterator<Item = (&crate::ImmutableString, &crate::Shared<crate::Module>)> {
|
||||
self.keys.iter().rev().zip(self.modules.iter().rev())
|
||||
}
|
||||
/// Get an iterator to the stack of globally-imported [modules][crate::Module] in forward order.
|
||||
@ -216,7 +216,7 @@ impl GlobalRuntimeState<'_> {
|
||||
#[inline]
|
||||
pub fn scan_imports_raw(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (&ImmutableString, &crate::Shared<crate::Module>)> {
|
||||
) -> impl Iterator<Item = (&crate::ImmutableString, &crate::Shared<crate::Module>)> {
|
||||
self.keys.iter().zip(self.modules.iter())
|
||||
}
|
||||
/// Does the specified function hash key exist in the stack of globally-imported
|
||||
@ -310,9 +310,9 @@ impl GlobalRuntimeState<'_> {
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
impl IntoIterator for GlobalRuntimeState<'_> {
|
||||
type Item = (ImmutableString, crate::Shared<crate::Module>);
|
||||
type Item = (crate::ImmutableString, crate::Shared<crate::Module>);
|
||||
type IntoIter = std::iter::Zip<
|
||||
std::iter::Rev<smallvec::IntoIter<[ImmutableString; 3]>>,
|
||||
std::iter::Rev<smallvec::IntoIter<[crate::ImmutableString; 3]>>,
|
||||
std::iter::Rev<smallvec::IntoIter<[crate::Shared<crate::Module>; 3]>>,
|
||||
>;
|
||||
|
||||
@ -327,9 +327,9 @@ impl IntoIterator for GlobalRuntimeState<'_> {
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
|
||||
type Item = (&'a ImmutableString, &'a crate::Shared<crate::Module>);
|
||||
type Item = (&'a crate::ImmutableString, &'a crate::Shared<crate::Module>);
|
||||
type IntoIter = std::iter::Zip<
|
||||
std::iter::Rev<std::slice::Iter<'a, ImmutableString>>,
|
||||
std::iter::Rev<std::slice::Iter<'a, crate::ImmutableString>>,
|
||||
std::iter::Rev<std::slice::Iter<'a, crate::Shared<crate::Module>>>,
|
||||
>;
|
||||
|
||||
@ -341,7 +341,7 @@ impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
impl<K: Into<ImmutableString>, M: Into<crate::Shared<crate::Module>>> Extend<(K, M)>
|
||||
impl<K: Into<crate::ImmutableString>, M: Into<crate::Shared<crate::Module>>> Extend<(K, M)>
|
||||
for GlobalRuntimeState<'_>
|
||||
{
|
||||
#[inline]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::def_package;
|
||||
use crate::plugin::*;
|
||||
use crate::types::{dynamic::Tag, StringsInterner};
|
||||
use crate::types::dynamic::Tag;
|
||||
use crate::{Dynamic, RhaiResultOf, ERR, INT};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@ -129,12 +129,12 @@ fn collect_fn_metadata(
|
||||
filter: impl Fn(FnNamespace, FnAccess, &str, usize, &crate::Shared<crate::ast::ScriptFnDef>) -> bool
|
||||
+ Copy,
|
||||
) -> crate::Array {
|
||||
use crate::{ast::ScriptFnDef, Array, Identifier, Map};
|
||||
use crate::{ast::ScriptFnDef, Array, Map};
|
||||
|
||||
// Create a metadata record for a function.
|
||||
fn make_metadata(
|
||||
dict: &mut StringsInterner,
|
||||
#[cfg(not(feature = "no_module"))] namespace: Identifier,
|
||||
dict: &mut crate::types::StringsInterner,
|
||||
#[cfg(not(feature = "no_module"))] namespace: crate::Identifier,
|
||||
func: &ScriptFnDef,
|
||||
) -> Map {
|
||||
let mut map = Map::new();
|
||||
@ -179,7 +179,7 @@ fn collect_fn_metadata(
|
||||
map
|
||||
}
|
||||
|
||||
let dict = &mut StringsInterner::new();
|
||||
let dict = &mut crate::types::StringsInterner::new();
|
||||
let mut list = Array::new();
|
||||
|
||||
ctx.iter_namespaces()
|
||||
@ -190,7 +190,7 @@ fn collect_fn_metadata(
|
||||
make_metadata(
|
||||
dict,
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Identifier::new_const(),
|
||||
crate::Identifier::new_const(),
|
||||
f,
|
||||
)
|
||||
.into(),
|
||||
@ -207,7 +207,7 @@ fn collect_fn_metadata(
|
||||
make_metadata(
|
||||
dict,
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Identifier::new_const(),
|
||||
crate::Identifier::new_const(),
|
||||
f,
|
||||
)
|
||||
.into(),
|
||||
@ -225,7 +225,7 @@ fn collect_fn_metadata(
|
||||
make_metadata(
|
||||
dict,
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Identifier::new_const(),
|
||||
crate::Identifier::new_const(),
|
||||
f,
|
||||
)
|
||||
.into(),
|
||||
@ -236,7 +236,7 @@ fn collect_fn_metadata(
|
||||
{
|
||||
// Recursively scan modules for script-defined functions.
|
||||
fn scan_module(
|
||||
dict: &mut StringsInterner,
|
||||
dict: &mut crate::types::StringsInterner,
|
||||
list: &mut Array,
|
||||
namespace: &str,
|
||||
module: &Module,
|
||||
|
@ -83,6 +83,7 @@ pub trait Package {
|
||||
///
|
||||
/// package.register_into_engine_as(&mut engine, "core");
|
||||
/// ```
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
fn register_into_engine_as(&self, engine: &mut Engine, name: &str) -> &Self {
|
||||
Self::init_engine(engine);
|
||||
engine.register_static_module(name, self.as_shared_module());
|
||||
|
@ -187,12 +187,13 @@ impl<'e> ParseState<'e> {
|
||||
lib: &FnLib,
|
||||
pos: Position,
|
||||
) -> (Option<NonZeroUsize>, bool) {
|
||||
let _lib = lib;
|
||||
let _pos = pos;
|
||||
|
||||
let (index, hit_barrier) = self.find_var(name);
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
let is_func_name = lib.values().any(|f| f.name == name);
|
||||
let is_func_name = _lib.values().any(|f| f.name == name);
|
||||
|
||||
#[cfg(feature = "no_function")]
|
||||
let is_func_name = false;
|
||||
|
@ -2,7 +2,7 @@
|
||||
#![cfg(feature = "metadata")]
|
||||
|
||||
use crate::module::{calc_native_fn_hash, FuncInfo};
|
||||
use crate::{calc_fn_hash, Engine, FnAccess, FnNamespace, SmartString, StaticVec, AST};
|
||||
use crate::{calc_fn_hash, Engine, FnAccess, SmartString, StaticVec, AST};
|
||||
use serde::Serialize;
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@ -30,7 +30,7 @@ struct FnMetadata<'a> {
|
||||
pub base_hash: u64,
|
||||
pub full_hash: u64,
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
pub namespace: FnNamespace,
|
||||
pub namespace: crate::FnNamespace,
|
||||
pub access: FnAccess,
|
||||
pub name: &'a str,
|
||||
#[serde(rename = "type")]
|
||||
@ -184,7 +184,7 @@ pub fn gen_metadata_to_json(
|
||||
let mut meta: FnMetadata = f.into();
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
{
|
||||
meta.namespace = FnNamespace::Global;
|
||||
meta.namespace = crate::FnNamespace::Global;
|
||||
}
|
||||
global.functions.push(meta);
|
||||
});
|
||||
@ -196,7 +196,7 @@ pub fn gen_metadata_to_json(
|
||||
let mut meta: FnMetadata = f.into();
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
{
|
||||
meta.namespace = FnNamespace::Global;
|
||||
meta.namespace = crate::FnNamespace::Global;
|
||||
}
|
||||
global.functions.push(meta);
|
||||
}
|
||||
|
@ -333,22 +333,29 @@ impl Span {
|
||||
}
|
||||
|
||||
impl fmt::Display for Span {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let _f = f;
|
||||
|
||||
#[cfg(not(feature = "no_position"))]
|
||||
match (self.start(), self.end()) {
|
||||
(Position::NONE, Position::NONE) => write!(f, "{:?}", Position::NONE),
|
||||
(Position::NONE, end) => write!(f, "..{:?}", end),
|
||||
(start, Position::NONE) => write!(f, "{:?}", start),
|
||||
(Position::NONE, Position::NONE) => write!(_f, "{:?}", Position::NONE),
|
||||
(Position::NONE, end) => write!(_f, "..{:?}", end),
|
||||
(start, Position::NONE) => write!(_f, "{:?}", start),
|
||||
(start, end) if start.line() != end.line() => {
|
||||
write!(f, "{:?}-{:?}", start, end)
|
||||
write!(_f, "{:?}-{:?}", start, end)
|
||||
}
|
||||
(start, end) => write!(
|
||||
f,
|
||||
_f,
|
||||
"{}:{}-{}",
|
||||
start.line().unwrap(),
|
||||
start.position().unwrap_or(0),
|
||||
end.position().unwrap_or(0)
|
||||
),
|
||||
}
|
||||
|
||||
#[cfg(feature = "no_position")]
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Helper module which defines the [`Dynamic`] data type and the
|
||||
//! [`Any`] trait to to allow custom type handling.
|
||||
|
||||
use crate::func::{locked_read, SendSync};
|
||||
use crate::func::SendSync;
|
||||
use crate::{reify, ExclusiveRange, FnPtr, ImmutableString, InclusiveRange, INT};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@ -23,6 +23,7 @@ pub use std::time::Instant;
|
||||
pub use instant::Instant;
|
||||
|
||||
/// The message: data type was checked
|
||||
#[allow(dead_code)]
|
||||
const CHECKED: &str = "data type was checked";
|
||||
|
||||
mod private {
|
||||
@ -427,7 +428,7 @@ impl Dynamic {
|
||||
Union::Variant(ref v, ..) => (***v).type_id(),
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, ..) => (*locked_read(cell)).type_id(),
|
||||
Union::Shared(ref cell, ..) => (*crate::func::locked_read(cell)).type_id(),
|
||||
}
|
||||
}
|
||||
/// Get the name of the type of the value held by this [`Dynamic`].
|
||||
@ -501,7 +502,7 @@ impl Hash for Dynamic {
|
||||
Union::FnPtr(ref f, ..) => f.hash(state),
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, ..) => (*locked_read(cell)).hash(state),
|
||||
Union::Shared(ref cell, ..) => (*crate::func::locked_read(cell)).hash(state),
|
||||
|
||||
Union::Variant(..) => unimplemented!("{} cannot be hashed", self.type_name()),
|
||||
|
||||
@ -1073,7 +1074,7 @@ impl Dynamic {
|
||||
pub fn is_read_only(&self) -> bool {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
if let Union::Shared(ref cell, ..) = self.0 {
|
||||
return match locked_read(cell).access_mode() {
|
||||
return match crate::func::locked_read(cell).access_mode() {
|
||||
ReadWrite => false,
|
||||
ReadOnly => true,
|
||||
};
|
||||
@ -1102,7 +1103,7 @@ impl Dynamic {
|
||||
Union::Map(..) => true,
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, ..) => locked_read(cell).is_hashable(),
|
||||
Union::Shared(ref cell, ..) => crate::func::locked_read(cell).is_hashable(),
|
||||
|
||||
_ => false,
|
||||
}
|
||||
@ -1353,7 +1354,7 @@ impl Dynamic {
|
||||
pub fn flatten_clone(&self) -> Self {
|
||||
match self.0 {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, ..) => locked_read(cell).clone(),
|
||||
Union::Shared(ref cell, ..) => crate::func::locked_read(cell).clone(),
|
||||
_ => self.clone(),
|
||||
}
|
||||
}
|
||||
@ -1369,7 +1370,7 @@ impl Dynamic {
|
||||
match self.0 {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(cell, ..) => crate::func::shared_try_take(cell).map_or_else(
|
||||
|ref cell| locked_read(cell).clone(),
|
||||
|ref cell| crate::func::locked_read(cell).clone(),
|
||||
#[cfg(not(feature = "sync"))]
|
||||
|value| value.into_inner(),
|
||||
#[cfg(feature = "sync")]
|
||||
@ -1391,7 +1392,7 @@ impl Dynamic {
|
||||
Union::Shared(ref mut cell, ..) => {
|
||||
let cell = mem::take(cell);
|
||||
*self = crate::func::shared_try_take(cell).map_or_else(
|
||||
|ref cell| locked_read(cell).clone(),
|
||||
|ref cell| crate::func::locked_read(cell).clone(),
|
||||
#[cfg(not(feature = "sync"))]
|
||||
|value| value.into_inner(),
|
||||
#[cfg(feature = "sync")]
|
||||
@ -1440,7 +1441,7 @@ impl Dynamic {
|
||||
match self.0 {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, ..) => {
|
||||
let value = locked_read(cell);
|
||||
let value = crate::func::locked_read(cell);
|
||||
|
||||
return if (*value).type_id() != TypeId::of::<T>()
|
||||
&& TypeId::of::<Dynamic>() != TypeId::of::<T>()
|
||||
@ -1788,7 +1789,7 @@ impl Dynamic {
|
||||
Union::Str(s, ..) => Ok(s),
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, ..) => {
|
||||
let value = locked_read(cell);
|
||||
let value = crate::func::locked_read(cell);
|
||||
|
||||
match value.0 {
|
||||
Union::Str(ref s, ..) => Ok(s.clone()),
|
||||
@ -1807,7 +1808,7 @@ impl Dynamic {
|
||||
Union::Array(a, ..) => Ok(*a),
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, ..) => {
|
||||
let value = locked_read(cell);
|
||||
let value = crate::func::locked_read(cell);
|
||||
|
||||
match value.0 {
|
||||
Union::Array(ref a, ..) => Ok(a.as_ref().clone()),
|
||||
@ -1842,7 +1843,7 @@ impl Dynamic {
|
||||
Union::Blob(..) if TypeId::of::<T>() == TypeId::of::<u8>() => Ok(self.cast::<Vec<T>>()),
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, ..) => {
|
||||
let value = locked_read(cell);
|
||||
let value = crate::func::locked_read(cell);
|
||||
|
||||
match value.0 {
|
||||
Union::Array(ref a, ..) => {
|
||||
@ -1880,7 +1881,7 @@ impl Dynamic {
|
||||
Union::Blob(a, ..) => Ok(*a),
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(ref cell, ..) => {
|
||||
let value = locked_read(cell);
|
||||
let value = crate::func::locked_read(cell);
|
||||
|
||||
match value.0 {
|
||||
Union::Blob(ref a, ..) => Ok(a.as_ref().clone()),
|
||||
|
@ -127,6 +127,7 @@ impl StringsInterner<'_> {
|
||||
/// Number of strings interned.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[allow(dead_code)]
|
||||
pub fn len(&self) -> usize {
|
||||
self.strings.len()
|
||||
}
|
||||
@ -134,12 +135,14 @@ impl StringsInterner<'_> {
|
||||
/// Returns `true` if there are no interned strings.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[allow(dead_code)]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.strings.is_empty()
|
||||
}
|
||||
|
||||
/// Clear all interned strings.
|
||||
#[inline(always)]
|
||||
#[allow(dead_code)]
|
||||
pub fn clear(&mut self) {
|
||||
self.strings.clear();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ def_package! {
|
||||
m.set_native_fn("hello", |x: INT| Ok(x + 1));
|
||||
m.set_native_fn("@", |x: INT, y: INT| Ok(x * x + y * y));
|
||||
} |> |engine| {
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
engine.register_custom_operator("@", 160).unwrap();
|
||||
}
|
||||
}
|
||||
@ -30,11 +31,20 @@ fn test_packages() -> Result<(), Box<EvalAltResult>> {
|
||||
scope.push("x", x);
|
||||
|
||||
// Evaluate script.
|
||||
engine.eval_with_scope::<INT>(&mut scope, "hello(x) @ foo::hello(x)")
|
||||
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
return engine.eval_with_scope::<INT>(&mut scope, "hello(x) @ foo::hello(x)");
|
||||
|
||||
#[cfg(feature = "no_custom_syntax")]
|
||||
return engine.eval_with_scope::<INT>(&mut scope, "hello(x) + foo::hello(x)");
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
assert_eq!(make_call(42)?, 3698);
|
||||
|
||||
#[cfg(feature = "no_custom_syntax")]
|
||||
assert_eq!(make_call(42)?, 86);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user