Skip to content

Commit

Permalink
Fix builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Jan 19, 2024
1 parent 86fc754 commit c65298a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Potentially breaking changes
* Traits implemented by `ImmutableString` are cleaned up. Normally this should not be a breaking change.
* `EvalContext::new`, `FloatWrapper` and `ConditionalExpr` are now gated under `internals`.
* Previously, Rhai follows [Unicode's definition for _whitespace_](https://en.wikipedia.org/wiki/Template:Whitespace_(Unicode)), which allows many exotic whitespace characters in scripts. Starting from this version, whitespace follows [WhatWG](https://infra.spec.whatwg.org/#ascii-whitespace)'s definition of five ASCII characters (TAB, SPACE, CR, LF and FF), which is the same as Rust. All other Unicode whitespace characters (not inside strings) are not considered whitespace by Rhai. If a script used to contain non-ASCII whitespace characters, it now fails to parse with a syntax error.
* `RegisterNativeFunction`, `CallableFunction`, `PluginFunction` are renamed `RhaiNativeFunc` and `RhaiFunc`, `PluginFunc` respectively to be consistent with naming.

Deprecated API's
----------------
Expand Down
2 changes: 1 addition & 1 deletion src/eval/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl GlobalRuntimeState {
#[cfg(not(feature = "no_module"))]
#[inline]
#[must_use]
pub fn get_iter(&self, id: std::any::TypeId) -> Option<&crate::func::IteratorFn> {
pub fn get_iter(&self, id: std::any::TypeId) -> Option<&crate::func::FnIterator> {
self.modules
.iter()
.rev()
Expand Down
6 changes: 3 additions & 3 deletions src/func/function.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Module defining the standard Rhai function type.
use super::native::{FnAny, FnPlugin, IteratorFn, SendSync};
use super::native::{FnAny, FnIterator, FnPlugin, SendSync};
use crate::ast::{EncapsulatedEnviron, FnAccess};
use crate::plugin::PluginFunc;
use crate::Shared;
Expand Down Expand Up @@ -43,7 +43,7 @@ pub enum RhaiFunc {
/// An iterator function.
Iterator {
/// Shared function pointer.
func: Shared<IteratorFn>,
func: Shared<FnIterator>,
},
/// A plugin function,
Plugin {
Expand Down Expand Up @@ -268,7 +268,7 @@ impl RhaiFunc {
/// Get a reference to an iterator function.
#[inline]
#[must_use]
pub fn get_iter_fn(&self) -> Option<&IteratorFn> {
pub fn get_iter_fn(&self) -> Option<&FnIterator> {
match self {
Self::Iterator { func, .. } => Some(&**func),
Self::Pure { .. } | Self::Method { .. } | Self::Plugin { .. } => None,
Expand Down
3 changes: 2 additions & 1 deletion src/func/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ pub use hashing::{calc_fn_hash, calc_fn_hash_full, calc_var_hash, get_hasher, St
#[cfg(feature = "internals")]
#[allow(deprecated)]
pub use native::NativeCallContextStore;
#[allow(unused_imports)]
pub use native::{
locked_read, locked_write, shared_get_mut, shared_make_mut, shared_take, shared_take_or_clone,
IteratorFn, Locked, NativeCallContext, SendSync, Shared,
FnIterator, Locked, NativeCallContext, SendSync, Shared,
};
pub use register::RhaiNativeFunc;
4 changes: 2 additions & 2 deletions src/func/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,10 @@ pub type FnBuiltin = (

/// Function that gets an iterator from a type.
#[cfg(not(feature = "sync"))]
pub type IteratorFn = dyn Fn(Dynamic) -> Box<dyn Iterator<Item = RhaiResultOf<Dynamic>>>;
pub type FnIterator = dyn Fn(Dynamic) -> Box<dyn Iterator<Item = RhaiResultOf<Dynamic>>>;
/// Function that gets an iterator from a type.
#[cfg(feature = "sync")]
pub type IteratorFn =
pub type FnIterator =
dyn Fn(Dynamic) -> Box<dyn Iterator<Item = RhaiResultOf<Dynamic>>> + Send + Sync;

/// Plugin function trait object.
Expand Down
19 changes: 12 additions & 7 deletions src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::api::formatting::format_type;
use crate::ast::FnAccess;
use crate::func::{
shared_take_or_clone, IteratorFn, RhaiFunc, RhaiNativeFunc, SendSync, StraightHashMap,
shared_take_or_clone, FnIterator, RhaiFunc, RhaiNativeFunc, SendSync, StraightHashMap,
};
use crate::types::{dynamic::Variant, BloomFilterU64, CustomTypeInfo, CustomTypesCollection};
use crate::{
Expand Down Expand Up @@ -360,9 +360,9 @@ pub struct Module {
/// Bloom filter on native Rust functions (in scripted hash format) that contain [`Dynamic`] parameters.
dynamic_functions_filter: BloomFilterU64,
/// Iterator functions, keyed by the type producing the iterator.
type_iterators: BTreeMap<TypeId, Shared<IteratorFn>>,
type_iterators: BTreeMap<TypeId, Shared<FnIterator>>,
/// Flattened collection of iterator functions, including those in sub-modules.
all_type_iterators: BTreeMap<TypeId, Shared<IteratorFn>>,
all_type_iterators: BTreeMap<TypeId, Shared<FnIterator>>,
/// Flags.
pub(crate) flags: ModuleFlags,
}
Expand Down Expand Up @@ -399,7 +399,12 @@ impl fmt::Debug for Module {
"functions",
&self
.iter_fn()
.map(|(_, f)| f.gen_signature())
.map(|(_f, _m)| {
#[cfg(not(feature = "metadata"))]
return _f.to_string();
#[cfg(feature = "metadata")]
return _m.gen_signature();
})
.collect::<Vec<_>>(),
)
.field("flags", &self.flags);
Expand Down Expand Up @@ -2156,7 +2161,7 @@ impl Module {
path: &mut Vec<&'a str>,
variables: &mut StraightHashMap<Dynamic>,
functions: &mut StraightHashMap<RhaiFunc>,
type_iterators: &mut BTreeMap<TypeId, Shared<IteratorFn>>,
type_iterators: &mut BTreeMap<TypeId, Shared<FnIterator>>,
) -> bool {
let mut contains_indexed_global_functions = false;

Expand Down Expand Up @@ -2383,14 +2388,14 @@ impl Module {
#[cfg(not(feature = "no_module"))]
#[inline]
#[must_use]
pub(crate) fn get_qualified_iter(&self, id: TypeId) -> Option<&IteratorFn> {
pub(crate) fn get_qualified_iter(&self, id: TypeId) -> Option<&FnIterator> {
self.all_type_iterators.get(&id).map(|f| &**f)
}

/// Get the specified type iterator.
#[inline]
#[must_use]
pub(crate) fn get_iter(&self, id: TypeId) -> Option<&IteratorFn> {
pub(crate) fn get_iter(&self, id: TypeId) -> Option<&FnIterator> {
self.type_iterators.get(&id).map(|f| &**f)
}
}
Expand Down

0 comments on commit c65298a

Please sign in to comment.