diff --git a/examples/definitions/main.rs b/examples/definitions/main.rs index 0638f8e8..f83ac4fd 100644 --- a/examples/definitions/main.rs +++ b/examples/definitions/main.rs @@ -18,11 +18,15 @@ fn main() { // since it will be part of the scope. scope.push("hello_there", "hello there"); + #[cfg(not(feature = "no_module"))] engine.register_static_module("general_kenobi", exported_module!(general_kenobi).into()); // Custom operators also show up in definitions. - engine.register_custom_operator("minus", 100).unwrap(); - engine.register_fn("minus", |a: i64, b: i64| a - b); + #[cfg(not(feature = "no_custom_syntax"))] + { + engine.register_custom_operator("minus", 100).unwrap(); + engine.register_fn("minus", |a: i64, b: i64| a - b); + } engine .eval_with_scope::<()>( diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index c983dc18..94e600a5 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -169,29 +169,32 @@ impl<'e> Definitions<'e> { s } - /// Return name and definition pairs for each registered module. + /// Return module name and definition pairs for each registered module. /// /// The definitions will always start with `module ;`. /// /// If the feature `no_module` is enabled, this will yield no elements. pub fn modules(&self) -> impl Iterator + '_ { #[cfg(not(feature = "no_module"))] - let mut m = self - .engine - .global_sub_modules - .iter() - .map(move |(name, module)| { - ( - name.to_string(), - format!("module {name};\n\n{}", module.definition(self)), - ) - }) - .collect::>(); + let m = { + let mut m = self + .engine + .global_sub_modules + .iter() + .map(move |(name, module)| { + ( + name.to_string(), + format!("module {name};\n\n{}", module.definition(self)), + ) + }) + .collect::>(); + + m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2)); + m + }; #[cfg(feature = "no_module")] - let mut m = Vec::new(); - - m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2)); + let m = Vec::new(); m.into_iter() }