Fix metadata build.

This commit is contained in:
Stephen Chung 2021-08-30 10:25:24 +08:00
parent a95f07fef5
commit b6d38a8fc9
3 changed files with 20 additions and 9 deletions

View File

@ -5,7 +5,7 @@ error[E0277]: the trait bound `NonClonable: Clone` is not satisfied
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NonClonable` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NonClonable`
| |
note: required by a bound in `rhai::Dynamic::from` note: required by a bound in `rhai::Dynamic::from`
--> $DIR/dynamic.rs:1127:30 --> $DIR/dynamic.rs:1121:30
| |
1127 | pub fn from<T: Variant + Clone>(mut value: T) -> Self { 1121 | pub fn from<T: Variant + Clone>(mut value: T) -> Self {
| ^^^^^ required by this bound in `rhai::Dynamic::from` | ^^^^^ required by this bound in `rhai::Dynamic::from`

View File

@ -24,7 +24,16 @@ use crate::Map;
impl Engine { impl Engine {
/// Get the global namespace module (which is the last module in `global_modules`). /// Get the global namespace module (which is the last module in `global_modules`).
#[inline(always)] #[inline(always)]
fn global_namespace(&mut self) -> &mut Module { #[allow(dead_code)]
pub(crate) fn global_namespace(&self) -> &Module {
self.global_modules
.last()
.expect("global_modules contains at least one module")
}
/// Get a mutable reference to the global namespace module
/// (which is the last module in `global_modules`).
#[inline(always)]
pub(crate) fn global_namespace_mut(&mut self) -> &mut Module {
Shared::get_mut( Shared::get_mut(
self.global_modules self.global_modules
.last_mut() .last_mut()
@ -84,7 +93,7 @@ impl Engine {
#[cfg(not(feature = "metadata"))] #[cfg(not(feature = "metadata"))]
let param_type_names: Option<[&str; 0]> = None; let param_type_names: Option<[&str; 0]> = None;
self.global_namespace().set_fn( self.global_namespace_mut().set_fn(
name, name,
FnNamespace::Global, FnNamespace::Global,
FnAccess::Public, FnAccess::Public,
@ -142,7 +151,7 @@ impl Engine {
#[cfg(not(feature = "metadata"))] #[cfg(not(feature = "metadata"))]
let param_type_names: Option<[&str; 0]> = None; let param_type_names: Option<[&str; 0]> = None;
self.global_namespace().set_fn( self.global_namespace_mut().set_fn(
name, name,
FnNamespace::Global, FnNamespace::Global,
FnAccess::Public, FnAccess::Public,
@ -181,7 +190,7 @@ impl Engine {
N: AsRef<str> + Into<Identifier>, N: AsRef<str> + Into<Identifier>,
T: Variant + Clone, T: Variant + Clone,
{ {
self.global_namespace().set_raw_fn( self.global_namespace_mut().set_raw_fn(
name, name,
FnNamespace::Global, FnNamespace::Global,
FnAccess::Public, FnAccess::Public,
@ -285,7 +294,7 @@ impl Engine {
T: Variant + Clone + IntoIterator, T: Variant + Clone + IntoIterator,
<T as IntoIterator>::Item: Variant + Clone, <T as IntoIterator>::Item: Variant + Clone,
{ {
self.global_namespace().set_iterable::<T>(); self.global_namespace_mut().set_iterable::<T>();
self self
} }
/// Register a getter function for a member of a registered type with the [`Engine`]. /// Register a getter function for a member of a registered type with the [`Engine`].
@ -2046,7 +2055,7 @@ impl Engine {
pub fn gen_fn_signatures(&self, include_packages: bool) -> Vec<String> { pub fn gen_fn_signatures(&self, include_packages: bool) -> Vec<String> {
let mut signatures: Vec<_> = Default::default(); let mut signatures: Vec<_> = Default::default();
signatures.extend(self.global_namespace.gen_fn_signatures()); signatures.extend(self.global_namespace().gen_fn_signatures());
self.global_sub_modules.iter().for_each(|(name, m)| { self.global_sub_modules.iter().for_each(|(name, m)| {
signatures.extend(m.gen_fn_signatures().map(|f| format!("{}::{}", name, f))) signatures.extend(m.gen_fn_signatures().map(|f| format!("{}::{}", name, f)))
@ -2056,6 +2065,7 @@ impl Engine {
signatures.extend( signatures.extend(
self.global_modules self.global_modules
.iter() .iter()
.take(self.global_modules.len() - 1)
.flat_map(|m| m.gen_fn_signatures()), .flat_map(|m| m.gen_fn_signatures()),
); );
} }

View File

@ -244,6 +244,7 @@ impl Engine {
if include_global { if include_global {
self.global_modules self.global_modules
.iter() .iter()
.take(self.global_modules.len() - 1)
.flat_map(|m| m.iter_fn()) .flat_map(|m| m.iter_fn())
.for_each(|f| global.functions.push(f.into())); .for_each(|f| global.functions.push(f.into()));
} }
@ -252,7 +253,7 @@ impl Engine {
global.modules.insert(name.to_string(), m.as_ref().into()); global.modules.insert(name.to_string(), m.as_ref().into());
}); });
self.global_namespace self.global_namespace()
.iter_fn() .iter_fn()
.for_each(|f| global.functions.push(f.into())); .for_each(|f| global.functions.push(f.into()));