From adbb5f8eb8d117be0e8d0fa9229eb5b89a806a44 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 25 Mar 2021 14:02:50 +0800 Subject: [PATCH] Use static array for codegen parameters info. --- CHANGELOG.md | 2 + codegen/src/function.rs | 64 +- codegen/src/lib.rs | 12 +- codegen/src/rhai_module.rs | 26 +- codegen/src/test/function.rs | 199 ++--- codegen/src/test/module.rs | 691 +++++------------- codegen/ui_tests/rhai_mod_unknown_type.stderr | 2 +- src/plugin.rs | 11 +- 8 files changed, 233 insertions(+), 774 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 389748c8..91efdb6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ an object map is small. `HashMap` and `BTreeMap` have almost identical public API's so this change is unlikely to break existing code. +All function signature/metadata methods are now grouped under the umbrella `metadata` feature. + Breaking changes ---------------- diff --git a/codegen/src/function.rs b/codegen/src/function.rs index a6cef77a..03d42400 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -587,20 +587,14 @@ impl ExportedFn { let name: syn::Ident = syn::Ident::new(&format!("rhai_fn_{}", self.name()), self.name().span()); let impl_block = self.generate_impl("Token"); - let callable_block = self.generate_callable("Token"); - let param_names_block = self.generate_param_names("Token"); - let input_types_block = self.generate_input_types("Token"); let dyn_result_fn_block = self.generate_dynamic_fn(); let vis = self.visibility; quote! { #[automatically_derived] #vis mod #name { use super::*; - struct Token(); + pub struct Token(); #impl_block - #callable_block - #param_names_block - #input_types_block #dyn_result_fn_block } } @@ -613,7 +607,7 @@ impl ExportedFn { dynamic_signature.ident = syn::Ident::new("dynamic_result_fn", proc_macro2::Span::call_site()); dynamic_signature.output = syn::parse2::(quote! { - -> Result> + -> RhaiResult }) .unwrap(); let arguments: Vec = dynamic_signature @@ -649,48 +643,6 @@ impl ExportedFn { } } - pub fn generate_callable(&self, on_type_name: &str) -> proc_macro2::TokenStream { - let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span()); - let callable_fn_name: syn::Ident = syn::Ident::new( - &format!("{}_callable", on_type_name.to_lowercase()), - self.name().span(), - ); - quote! { - #[inline(always)] - pub fn #callable_fn_name() -> CallableFunction { - #token_name().into() - } - } - } - - pub fn generate_param_names(&self, on_type_name: &str) -> proc_macro2::TokenStream { - let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span()); - let param_names_fn_name: syn::Ident = syn::Ident::new( - &format!("{}_param_names", on_type_name.to_lowercase()), - self.name().span(), - ); - quote! { - #[inline(always)] - pub fn #param_names_fn_name() -> Box<[&'static str]> { - #token_name().param_names() - } - } - } - - pub fn generate_input_types(&self, on_type_name: &str) -> proc_macro2::TokenStream { - let token_name: syn::Ident = syn::Ident::new(on_type_name, self.name().span()); - let input_types_fn_name: syn::Ident = syn::Ident::new( - &format!("{}_input_types", on_type_name.to_lowercase()), - self.name().span(), - ); - quote! { - #[inline(always)] - pub fn #input_types_fn_name() -> Box<[TypeId]> { - #token_name().input_types() - } - } - } - pub fn generate_impl(&self, on_type_name: &str) -> proc_macro2::TokenStream { let sig_name = self.name().clone(); let arg_count = self.arg_count(); @@ -866,23 +818,19 @@ impl ExportedFn { let type_name = syn::Ident::new(on_type_name, proc_macro2::Span::call_site()); quote! { + impl #type_name { + pub const PARAM_NAMES: &'static [&'static str] = &[#(#input_type_names,)* #return_type]; + #[inline(always)] pub fn param_types() -> [TypeId; #arg_count] { [#(#input_type_exprs),*] } + } impl PluginFunction for #type_name { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), #arg_count, "wrong arg count: {} != {}", args.len(), #arg_count); #(#unpack_statements)* #return_expr } #[inline(always)] fn is_method_call(&self) -> bool { #is_method_call } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(#type_name()) } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec![#(#input_type_names,)* #return_type].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![#(#input_type_exprs),*].into_boxed_slice() - } } } } diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index 209b8227..e6af8fe2 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -332,9 +332,9 @@ pub fn set_exported_fn(args: proc_macro::TokenStream) -> proc_macro::TokenStream let gen_mod_path = crate::register::generated_module_path(&rust_mod_path); proc_macro::TokenStream::from(quote! { #module_expr.set_fn(#export_name, FnNamespace::Internal, FnAccess::Public, - Some(#gen_mod_path::token_param_names().as_ref()), - #gen_mod_path::token_input_types().as_ref(), - #gen_mod_path::token_callable()); + Some(#gen_mod_path::Token::PARAM_NAMES), + &#gen_mod_path::Token::param_types(), + #gen_mod_path::Token().into()); }) } Err(e) => e.to_compile_error().into(), @@ -373,9 +373,9 @@ pub fn set_exported_global_fn(args: proc_macro::TokenStream) -> proc_macro::Toke let gen_mod_path = crate::register::generated_module_path(&rust_mod_path); proc_macro::TokenStream::from(quote! { #module_expr.set_fn(#export_name, FnNamespace::Global, FnAccess::Public, - Some(#gen_mod_path::token_param_names().as_ref()), - #gen_mod_path::token_input_types().as_ref(), - #gen_mod_path::token_callable()); + Some(#gen_mod_path::Token::PARAM_NAMES), + &#gen_mod_path::Token::param_types(), + #gen_mod_path::Token().into()); }) } Err(e) => e.to_compile_error().into(), diff --git a/codegen/src/rhai_module.rs b/codegen/src/rhai_module.rs index b1eb1947..11c8d1de 100644 --- a/codegen/src/rhai_module.rs +++ b/codegen/src/rhai_module.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use quote::{quote, ToTokens}; +use quote::quote; use crate::attrs::ExportScope; use crate::function::{ @@ -81,16 +81,6 @@ pub fn generate_body( ); let reg_names = function.exported_names(); - let fn_input_names: Vec = function - .arg_list() - .map(|fn_arg| match fn_arg { - syn::FnArg::Receiver(_) => panic!("internal error: receiver fn outside impl!?"), - syn::FnArg::Typed(syn::PatType { pat, ty, .. }) => { - format!("{}: {}", pat.to_token_stream(), print_type(ty)) - } - }) - .collect(); - let fn_input_types: Vec = function .arg_list() .map(|fn_arg| match fn_arg { @@ -128,17 +118,12 @@ pub fn generate_body( }; syn::parse2::(quote! { - core::any::TypeId::of::<#arg_type>()}) + TypeId::of::<#arg_type>()}) .unwrap() } }) .collect(); - let return_type = function - .return_type() - .map(print_type) - .unwrap_or_else(|| "()".to_string()); - for fn_literal in reg_names { let mut namespace = FnNamespaceAccess::Internal; @@ -172,7 +157,7 @@ pub fn generate_body( set_fn_statements.push( syn::parse2::(quote! { m.set_fn(#fn_literal, FnNamespace::#ns_str, FnAccess::Public, - Some(&[#(#fn_input_names,)* #return_type]), &[#(#fn_input_types),*], + Some(#fn_token_name::PARAM_NAMES), &[#(#fn_input_types),*], #fn_token_name().into()); }) .unwrap(), @@ -181,12 +166,9 @@ pub fn generate_body( gen_fn_tokens.push(quote! { #[allow(non_camel_case_types)] - struct #fn_token_name(); + pub struct #fn_token_name(); }); gen_fn_tokens.push(function.generate_impl(&fn_token_name.to_string())); - gen_fn_tokens.push(function.generate_callable(&fn_token_name.to_string())); - gen_fn_tokens.push(function.generate_param_names(&fn_token_name.to_string())); - gen_fn_tokens.push(function.generate_input_types(&fn_token_name.to_string())); } let mut generate_fn_call = syn::parse2::(quote! { diff --git a/codegen/src/test/function.rs b/codegen/src/test/function.rs index c0abce5b..a8a56d83 100644 --- a/codegen/src/test/function.rs +++ b/codegen/src/test/function.rs @@ -275,35 +275,21 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_do_nothing { use super::*; - struct Token(); + pub struct Token(); + impl Token { + pub const PARAM_NAMES: &'static [&'static str] = &["()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 0usize] { [] } + } impl PluginFunction for Token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 0usize, - "wrong arg count: {} != {}", args.len(), 0usize); Ok(Dynamic::from(do_nothing())) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![].into_boxed_slice() - } - } - #[inline(always)] pub fn token_callable() -> CallableFunction { - Token().into() - } - #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { - Token().param_names() - } - #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { - Token().input_types() } #[allow(unused)] - #[inline(always)] pub fn dynamic_result_fn() -> Result > { + #[inline(always)] pub fn dynamic_result_fn() -> RhaiResult { Ok(Dynamic::from(do_nothing())) } } @@ -323,37 +309,23 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_do_something { use super::*; - struct Token(); + pub struct Token(); + impl Token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: usize", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for Token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); let arg0 = mem::take(args[0usize]).cast::(); Ok(Dynamic::from(do_something(arg0))) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: usize", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn token_callable() -> CallableFunction { - Token().into() - } - #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { - Token().param_names() - } - #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { - Token().input_types() } #[allow(unused)] - #[inline(always)] pub fn dynamic_result_fn(x: usize) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(x: usize) -> RhaiResult { Ok(Dynamic::from(do_something(x))) } } @@ -373,37 +345,23 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_do_something { use super::*; - struct Token(); + pub struct Token(); + impl Token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: usize", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for Token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); let arg0 = mem::take(args[0usize]).cast::(); Ok(Dynamic::from(do_something(context, arg0))) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: usize", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn token_callable() -> CallableFunction { - Token().into() - } - #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { - Token().param_names() - } - #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { - Token().input_types() } #[allow(unused)] - #[inline(always)] pub fn dynamic_result_fn(context: NativeCallContext, x: usize) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(context: NativeCallContext, x: usize) -> RhaiResult { Ok(Dynamic::from(do_something(context, x))) } } @@ -426,36 +384,22 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_return_dynamic { use super::*; - struct Token(); + pub struct Token(); + impl Token { + pub const PARAM_NAMES: &'static [&'static str] = &["rhai::Dynamic"]; + #[inline(always)] pub fn param_types() -> [TypeId; 0usize] { [] } + } impl PluginFunction for Token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 0usize, - "wrong arg count: {} != {}", args.len(), 0usize); Ok(Dynamic::from(return_dynamic())) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["rhai::Dynamic"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![].into_boxed_slice() - } - } - #[inline(always)] pub fn token_callable() -> CallableFunction { - Token().into() - } - #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { - Token().param_names() - } - #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { - Token().input_types() } #[allow(unused)] - #[inline(always)] pub fn dynamic_result_fn() -> Result > { + #[inline(always)] pub fn dynamic_result_fn() -> RhaiResult { Ok(Dynamic::from(return_dynamic())) } } @@ -472,25 +416,20 @@ mod generate_tests { }; let expected_tokens = quote! { + impl TestStruct { + pub const PARAM_NAMES: &'static [&'static str] = &["x: usize", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for TestStruct { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); let arg0 = mem::take(args[0usize]).cast::(); Ok(Dynamic::from(do_something(arg0))) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(TestStruct()) } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: usize", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } + } }; let item_fn = syn::parse2::(input_tokens).unwrap(); @@ -507,12 +446,14 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_add_together { use super::*; - struct Token(); + pub struct Token(); + impl Token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: usize", "y: usize", "usize"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for Token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); let arg0 = mem::take(args[0usize]).cast::(); let arg1 = mem::take(args[1usize]).cast::(); Ok(Dynamic::from(add_together(arg0, arg1))) @@ -520,26 +461,9 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: usize", "y: usize", "usize"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), - TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn token_callable() -> CallableFunction { - Token().into() - } - #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { - Token().param_names() - } - #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { - Token().input_types() } #[allow(unused)] - #[inline(always)] pub fn dynamic_result_fn(x: usize, y: usize) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(x: usize, y: usize) -> RhaiResult { Ok(Dynamic::from(add_together(x, y))) } } @@ -559,12 +483,14 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_increment { use super::*; - struct Token(); + pub struct Token(); + impl Token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut usize", "y: usize", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for Token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -577,26 +503,9 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut usize", "y: usize", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), - TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn token_callable() -> CallableFunction { - Token().into() - } - #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { - Token().param_names() - } - #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { - Token().input_types() } #[allow(unused)] - #[inline(always)] pub fn dynamic_result_fn(x: &mut usize, y: usize) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(x: &mut usize, y: usize) -> RhaiResult { Ok(Dynamic::from(increment(x, y))) } } @@ -617,37 +526,23 @@ mod generate_tests { #[automatically_derived] pub mod rhai_fn_special_print { use super::*; - struct Token(); + pub struct Token(); + impl Token { + pub const PARAM_NAMES: &'static [&'static str] = &["message: &str", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for Token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); let arg0 = mem::take(args[0usize]).take_immutable_string().unwrap(); Ok(Dynamic::from(special_print(&arg0))) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { Box::new(Token()) } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["message: &str", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn token_callable() -> CallableFunction { - Token().into() - } - #[inline(always)] pub fn token_param_names() -> Box<[&'static str]> { - Token().param_names() - } - #[inline(always)] pub fn token_input_types() -> Box<[TypeId]> { - Token().input_types() } #[allow(unused)] - #[inline(always)] pub fn dynamic_result_fn(message: &str) -> Result > { + #[inline(always)] pub fn dynamic_result_fn(message: &str) -> RhaiResult { Ok(Dynamic::from(special_print(message))) } } diff --git a/codegen/src/test/module.rs b/codegen/src/test/module.rs index 61645c81..fdf4cf12 100644 --- a/codegen/src/test/module.rs +++ b/codegen/src/test/module.rs @@ -297,40 +297,25 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("get_mystic_number", FnNamespace::Internal, FnAccess::Public, Some(&["INT"]), &[], + m.set_fn("get_mystic_number", FnNamespace::Internal, FnAccess::Public, + Some(get_mystic_number_token::PARAM_NAMES), &[], get_mystic_number_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct get_mystic_number_token(); + pub struct get_mystic_number_token(); + impl get_mystic_number_token { + pub const PARAM_NAMES: &'static [&'static str] = &["INT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 0usize] { [] } + } impl PluginFunction for get_mystic_number_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 0usize, - "wrong arg count: {} != {}", args.len(), 0usize); Ok(Dynamic::from(get_mystic_number())) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(get_mystic_number_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["INT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![].into_boxed_slice() - } - } - #[inline(always)] pub fn get_mystic_number_token_callable() -> CallableFunction { - get_mystic_number_token().into() - } - #[inline(always)] pub fn get_mystic_number_token_param_names() -> Box<[&'static str]> { - get_mystic_number_token().param_names() - } - #[inline(always)] pub fn get_mystic_number_token_input_types() -> Box<[TypeId]> { - get_mystic_number_token().input_types() } } }; @@ -366,42 +351,26 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("add_one_to", FnNamespace::Global, FnAccess::Public, Some(&["x: INT", "INT"]), - &[core::any::TypeId::of::()], + m.set_fn("add_one_to", FnNamespace::Global, FnAccess::Public, + Some(add_one_to_token::PARAM_NAMES), &[TypeId::of::()], add_one_to_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct add_one_to_token(); + pub struct add_one_to_token(); + impl add_one_to_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "INT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for add_one_to_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); let arg0 = mem::take(args[0usize]).cast::(); Ok(Dynamic::from(add_one_to(arg0))) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(add_one_to_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT", "INT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn add_one_to_token_callable() -> CallableFunction { - add_one_to_token().into() - } - #[inline(always)] pub fn add_one_to_token_param_names() -> Box<[&'static str]> { - add_one_to_token().param_names() - } - #[inline(always)] pub fn add_one_to_token_input_types() -> Box<[TypeId]> { - add_one_to_token().input_types() } } }; @@ -436,42 +405,26 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("add_one_to", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "INT"]), - &[core::any::TypeId::of::()], + m.set_fn("add_one_to", FnNamespace::Internal, FnAccess::Public, Some(add_one_to_token::PARAM_NAMES), + &[TypeId::of::()], add_one_to_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct add_one_to_token(); + pub struct add_one_to_token(); + impl add_one_to_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "INT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for add_one_to_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); let arg0 = mem::take(args[0usize]).cast::(); Ok(Dynamic::from(add_one_to(arg0))) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(add_one_to_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT", "INT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn add_one_to_token_callable() -> CallableFunction { - add_one_to_token().into() - } - #[inline(always)] pub fn add_one_to_token_param_names() -> Box<[&'static str]> { - add_one_to_token().param_names() - } - #[inline(always)] pub fn add_one_to_token_input_types() -> Box<[TypeId]> { - add_one_to_token().input_types() } } }; @@ -517,54 +470,40 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("add_n", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "INT"]), - &[core::any::TypeId::of::()], + m.set_fn("add_n", FnNamespace::Internal, FnAccess::Public, Some(add_one_to_token::PARAM_NAMES), + &[TypeId::of::()], add_one_to_token().into()); - m.set_fn("add_n", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "y: INT", "INT"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("add_n", FnNamespace::Internal, FnAccess::Public, Some(add_n_to_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], add_n_to_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct add_one_to_token(); + pub struct add_one_to_token(); + impl add_one_to_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "INT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for add_one_to_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); let arg0 = mem::take(args[0usize]).cast::(); Ok(Dynamic::from(add_one_to(arg0))) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(add_one_to_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT", "INT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn add_one_to_token_callable() -> CallableFunction { - add_one_to_token().into() - } - #[inline(always)] pub fn add_one_to_token_param_names() -> Box<[&'static str]> { - add_one_to_token().param_names() - } - #[inline(always)] pub fn add_one_to_token_input_types() -> Box<[TypeId]> { - add_one_to_token().input_types() } #[allow(non_camel_case_types)] - struct add_n_to_token(); + pub struct add_n_to_token(); + impl add_n_to_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "y: INT", "INT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for add_n_to_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); let arg0 = mem::take(args[0usize]).cast::(); let arg1 = mem::take(args[1usize]).cast::(); Ok(Dynamic::from(add_n_to(arg0, arg1))) @@ -572,25 +511,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(add_n_to_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT", "y: INT", "INT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), - TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn add_n_to_token_callable() -> CallableFunction { - add_n_to_token().into() - } - #[inline(always)] pub fn add_n_to_token_param_names() -> Box<[&'static str]> { - add_n_to_token().param_names() - } - #[inline(always)] pub fn add_n_to_token_input_types() -> Box<[TypeId]> { - add_n_to_token().input_types() } } }; @@ -625,18 +545,20 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("add_together", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "y: INT", "INT"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("add_together", FnNamespace::Internal, FnAccess::Public, Some(add_together_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], add_together_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct add_together_token(); + pub struct add_together_token(); + impl add_together_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "y: INT", "INT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for add_together_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); let arg0 = mem::take(args[0usize]).cast::(); let arg1 = mem::take(args[1usize]).cast::(); Ok(Dynamic::from(add_together(arg0, arg1))) @@ -644,25 +566,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(add_together_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT", "y: INT", "INT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), - TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn add_together_token_callable() -> CallableFunction { - add_together_token().into() - } - #[inline(always)] pub fn add_together_token_param_names() -> Box<[&'static str]> { - add_together_token().param_names() - } - #[inline(always)] pub fn add_together_token_input_types() -> Box<[TypeId]> { - add_together_token().input_types() } } }; @@ -698,24 +601,26 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("add", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "y: INT", "INT"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("add", FnNamespace::Internal, FnAccess::Public, Some(add_together_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], add_together_token().into()); - m.set_fn("+", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "y: INT", "INT"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("+", FnNamespace::Internal, FnAccess::Public, Some(add_together_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], add_together_token().into()); - m.set_fn("add_together", FnNamespace::Internal, FnAccess::Public, Some(&["x: INT", "y: INT", "INT"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("add_together", FnNamespace::Internal, FnAccess::Public, Some(add_together_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], add_together_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct add_together_token(); + pub struct add_together_token(); + impl add_together_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: INT", "y: INT", "INT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for add_together_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); let arg0 = mem::take(args[0usize]).cast::(); let arg1 = mem::take(args[1usize]).cast::(); Ok(Dynamic::from(add_together(arg0, arg1))) @@ -723,25 +628,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(add_together_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: INT", "y: INT", "INT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), - TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn add_together_token_callable() -> CallableFunction { - add_together_token().into() - } - #[inline(always)] pub fn add_together_token_param_names() -> Box<[&'static str]> { - add_together_token().param_names() - } - #[inline(always)] pub fn add_together_token_input_types() -> Box<[TypeId]> { - add_together_token().input_types() } } }; @@ -958,40 +844,25 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("get_mystic_number", FnNamespace::Internal, FnAccess::Public, Some(&["INT"]), &[], + m.set_fn("get_mystic_number", FnNamespace::Internal, FnAccess::Public, + Some(get_mystic_number_token::PARAM_NAMES), &[], get_mystic_number_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct get_mystic_number_token(); + pub struct get_mystic_number_token(); + impl get_mystic_number_token { + pub const PARAM_NAMES: &'static [&'static str] = &["INT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 0usize] { [] } + } impl PluginFunction for get_mystic_number_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 0usize, - "wrong arg count: {} != {}", args.len(), 0usize); Ok(Dynamic::from(get_mystic_number())) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(get_mystic_number_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["INT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![].into_boxed_slice() - } - } - #[inline(always)] pub fn get_mystic_number_token_callable() -> CallableFunction { - get_mystic_number_token().into() - } - #[inline(always)] pub fn get_mystic_number_token_param_names() -> Box<[&'static str]> { - get_mystic_number_token().param_names() - } - #[inline(always)] pub fn get_mystic_number_token_input_types() -> Box<[TypeId]> { - get_mystic_number_token().input_types() } } }; @@ -1057,42 +928,26 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, Some(&["x: &str", "()"]), - &[core::any::TypeId::of::()], + m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, Some(print_out_to_token::PARAM_NAMES), + &[TypeId::of::()], print_out_to_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct print_out_to_token(); + pub struct print_out_to_token(); + impl print_out_to_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &str", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for print_out_to_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); let arg0 = mem::take(args[0usize]).take_immutable_string().unwrap(); Ok(Dynamic::from(print_out_to(&arg0))) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(print_out_to_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &str", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn print_out_to_token_callable() -> CallableFunction { - print_out_to_token().into() - } - #[inline(always)] pub fn print_out_to_token_param_names() -> Box<[&'static str]> { - print_out_to_token().param_names() - } - #[inline(always)] pub fn print_out_to_token_input_types() -> Box<[TypeId]> { - print_out_to_token().input_types() } } }; @@ -1127,42 +982,26 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, Some(&["x: String", "()"]), - &[core::any::TypeId::of::()], + m.set_fn("print_out_to", FnNamespace::Internal, FnAccess::Public, Some(print_out_to_token::PARAM_NAMES), + &[TypeId::of::()], print_out_to_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct print_out_to_token(); + pub struct print_out_to_token(); + impl print_out_to_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: String", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for print_out_to_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); let arg0 = mem::take(args[0usize]).take_string().unwrap(); Ok(Dynamic::from(print_out_to(arg0))) } #[inline(always)] fn is_method_call(&self) -> bool { false } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(print_out_to_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: String", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn print_out_to_token_callable() -> CallableFunction { - print_out_to_token().into() - } - #[inline(always)] pub fn print_out_to_token_param_names() -> Box<[&'static str]> { - print_out_to_token().param_names() - } - #[inline(always)] pub fn print_out_to_token_input_types() -> Box<[TypeId]> { - print_out_to_token().input_types() } } }; @@ -1198,18 +1037,20 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("foo", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut FLOAT", "y: INT", "FLOAT"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("foo", FnNamespace::Internal, FnAccess::Public, Some(foo_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], foo_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct foo_token(); + pub struct foo_token(); + impl foo_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut FLOAT", "y: INT", "FLOAT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for foo_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); let arg1 = mem::take(args[1usize]).cast::(); let arg0 = &mut args[0usize].write_lock::().unwrap(); Ok(Dynamic::from(foo(arg0, arg1))) @@ -1217,24 +1058,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(foo_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut FLOAT", "y: INT", "FLOAT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn foo_token_callable() -> CallableFunction { - foo_token().into() - } - #[inline(always)] pub fn foo_token_param_names() -> Box<[&'static str]> { - foo_token().param_names() - } - #[inline(always)] pub fn foo_token_input_types() -> Box<[TypeId]> { - foo_token().input_types() } } }; @@ -1269,18 +1092,20 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut FLOAT", "()"]), - &[core::any::TypeId::of::()], + m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(increment_token::PARAM_NAMES), + &[TypeId::of::()], increment_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct increment_token(); + pub struct increment_token(); + impl increment_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut FLOAT", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for increment_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -1292,24 +1117,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(increment_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut FLOAT", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn increment_token_callable() -> CallableFunction { - increment_token().into() - } - #[inline(always)] pub fn increment_token_param_names() -> Box<[&'static str]> { - increment_token().param_names() - } - #[inline(always)] pub fn increment_token_input_types() -> Box<[TypeId]> { - increment_token().input_types() } } }; @@ -1347,18 +1154,20 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut FLOAT", "()"]), - &[core::any::TypeId::of::()], + m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(increment_token::PARAM_NAMES), + &[TypeId::of::()], increment_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct increment_token(); + pub struct increment_token(); + impl increment_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut FLOAT", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for increment_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -1370,24 +1179,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(increment_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut FLOAT", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn increment_token_callable() -> CallableFunction { - increment_token().into() - } - #[inline(always)] pub fn increment_token_param_names() -> Box<[&'static str]> { - increment_token().param_names() - } - #[inline(always)] pub fn increment_token_input_types() -> Box<[TypeId]> { - increment_token().input_types() } } #[allow(unused_imports)] @@ -1446,18 +1237,20 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut FLOAT", "()"]), - &[core::any::TypeId::of::()], + m.set_fn("increment", FnNamespace::Internal, FnAccess::Public, Some(increment_token::PARAM_NAMES), + &[TypeId::of::()], increment_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct increment_token(); + pub struct increment_token(); + impl increment_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut FLOAT", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for increment_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -1469,24 +1262,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(increment_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut FLOAT", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn increment_token_callable() -> CallableFunction { - increment_token().into() - } - #[inline(always)] pub fn increment_token_param_names() -> Box<[&'static str]> { - increment_token().param_names() - } - #[inline(always)] pub fn increment_token_input_types() -> Box<[TypeId]> { - increment_token().input_types() } } #[allow(unused_imports)] @@ -1544,18 +1319,20 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("get$square", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut u64", "u64"]), - &[core::any::TypeId::of::()], + m.set_fn("get$square", FnNamespace::Global, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), + &[TypeId::of::()], int_foo_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct int_foo_token(); + pub struct int_foo_token(); + impl int_foo_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut u64", "u64"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for int_foo_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -1567,24 +1344,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(int_foo_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut u64", "u64"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn int_foo_token_callable() -> CallableFunction { - int_foo_token().into() - } - #[inline(always)] pub fn int_foo_token_param_names() -> Box<[&'static str]> { - int_foo_token().param_names() - } - #[inline(always)] pub fn int_foo_token_input_types() -> Box<[TypeId]> { - int_foo_token().input_types() } } }; @@ -1620,21 +1379,23 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("square", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut u64", "u64"]), - &[core::any::TypeId::of::()], + m.set_fn("square", FnNamespace::Internal, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), + &[TypeId::of::()], int_foo_token().into()); - m.set_fn("get$square", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut u64", "u64"]), - &[core::any::TypeId::of::()], + m.set_fn("get$square", FnNamespace::Global, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), + &[TypeId::of::()], int_foo_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct int_foo_token(); + pub struct int_foo_token(); + impl int_foo_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut u64", "u64"]; + #[inline(always)] pub fn param_types() -> [TypeId; 1usize] { [TypeId::of::()] } + } impl PluginFunction for int_foo_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 1usize, - "wrong arg count: {} != {}", args.len(), 1usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -1646,24 +1407,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(int_foo_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut u64", "u64"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn int_foo_token_callable() -> CallableFunction { - int_foo_token().into() - } - #[inline(always)] pub fn int_foo_token_param_names() -> Box<[&'static str]> { - int_foo_token().param_names() - } - #[inline(always)] pub fn int_foo_token_input_types() -> Box<[TypeId]> { - int_foo_token().input_types() } } }; @@ -1699,18 +1442,20 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("set$squared", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut u64", "y: u64", "()"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("set$squared", FnNamespace::Global, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], int_foo_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct int_foo_token(); + pub struct int_foo_token(); + impl int_foo_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut u64", "y: u64", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for int_foo_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -1723,24 +1468,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(int_foo_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut u64", "y: u64", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn int_foo_token_callable() -> CallableFunction { - int_foo_token().into() - } - #[inline(always)] pub fn int_foo_token_param_names() -> Box<[&'static str]> { - int_foo_token().param_names() - } - #[inline(always)] pub fn int_foo_token_input_types() -> Box<[TypeId]> { - int_foo_token().input_types() } } }; @@ -1776,21 +1503,23 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("set_sq", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut u64", "y: u64", "()"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("set_sq", FnNamespace::Internal, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], int_foo_token().into()); - m.set_fn("set$squared", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut u64", "y: u64", "()"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("set$squared", FnNamespace::Global, FnAccess::Public, Some(int_foo_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], int_foo_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct int_foo_token(); + pub struct int_foo_token(); + impl int_foo_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut u64", "y: u64", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for int_foo_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -1803,24 +1532,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(int_foo_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut u64", "y: u64", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn int_foo_token_callable() -> CallableFunction { - int_foo_token().into() - } - #[inline(always)] pub fn int_foo_token_param_names() -> Box<[&'static str]> { - int_foo_token().param_names() - } - #[inline(always)] pub fn int_foo_token_input_types() -> Box<[TypeId]> { - int_foo_token().input_types() } } }; @@ -1856,18 +1567,20 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(get_by_index_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], get_by_index_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct get_by_index_token(); + pub struct get_by_index_token(); + impl get_by_index_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut MyCollection", "i: u64", "FLOAT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for get_by_index_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -1880,25 +1593,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(get_by_index_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut MyCollection", "i: u64", "FLOAT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), - TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn get_by_index_token_callable() -> CallableFunction { - get_by_index_token().into() - } - #[inline(always)] pub fn get_by_index_token_param_names() -> Box<[&'static str]> { - get_by_index_token().param_names() - } - #[inline(always)] pub fn get_by_index_token_input_types() -> Box<[TypeId]> { - get_by_index_token().input_types() } } }; @@ -1934,21 +1628,23 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("get", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("get", FnNamespace::Internal, FnAccess::Public, Some(get_by_index_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], get_by_index_token().into()); - m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "FLOAT"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("index$get$", FnNamespace::Global, FnAccess::Public, Some(get_by_index_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::()], get_by_index_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct get_by_index_token(); + pub struct get_by_index_token(); + impl get_by_index_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut MyCollection", "i: u64", "FLOAT"]; + #[inline(always)] pub fn param_types() -> [TypeId; 2usize] { [TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for get_by_index_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 2usize, - "wrong arg count: {} != {}", args.len(), 2usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -1961,25 +1657,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(get_by_index_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut MyCollection", "i: u64", "FLOAT"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), - TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn get_by_index_token_callable() -> CallableFunction { - get_by_index_token().into() - } - #[inline(always)] pub fn get_by_index_token_param_names() -> Box<[&'static str]> { - get_by_index_token().param_names() - } - #[inline(always)] pub fn get_by_index_token_input_types() -> Box<[TypeId]> { - get_by_index_token().input_types() } } }; @@ -2015,18 +1692,20 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, Some(set_by_index_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::(), TypeId::of::()], set_by_index_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct set_by_index_token(); + pub struct set_by_index_token(); + impl set_by_index_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 3usize] { [TypeId::of::(), TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for set_by_index_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 3usize, - "wrong arg count: {} != {}", args.len(), 3usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -2040,26 +1719,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(set_by_index_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), - TypeId::of::(), - TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn set_by_index_token_callable() -> CallableFunction { - set_by_index_token().into() - } - #[inline(always)] pub fn set_by_index_token_param_names() -> Box<[&'static str]> { - set_by_index_token().param_names() - } - #[inline(always)] pub fn set_by_index_token_input_types() -> Box<[TypeId]> { - set_by_index_token().input_types() } } }; @@ -2095,21 +1754,23 @@ mod generate_tests { } #[allow(unused_mut)] pub fn rhai_generate_into_module(m: &mut Module, flatten: bool) { - m.set_fn("set", FnNamespace::Internal, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("set", FnNamespace::Internal, FnAccess::Public, Some(set_by_index_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::(), TypeId::of::()], set_by_index_token().into()); - m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, Some(&["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]), - &[core::any::TypeId::of::(), core::any::TypeId::of::(), core::any::TypeId::of::()], + m.set_fn("index$set$", FnNamespace::Global, FnAccess::Public, Some(set_by_index_token::PARAM_NAMES), + &[TypeId::of::(), TypeId::of::(), TypeId::of::()], set_by_index_token().into()); if flatten {} else {} } #[allow(non_camel_case_types)] - struct set_by_index_token(); + pub struct set_by_index_token(); + impl set_by_index_token { + pub const PARAM_NAMES: &'static [&'static str] = &["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"]; + #[inline(always)] pub fn param_types() -> [TypeId; 3usize] { [TypeId::of::(), TypeId::of::(), TypeId::of::()] } + } impl PluginFunction for set_by_index_token { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { - debug_assert_eq!(args.len(), 3usize, - "wrong arg count: {} != {}", args.len(), 3usize); if args[0usize].is_read_only() { return Err(Box::new( EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE) @@ -2123,26 +1784,6 @@ mod generate_tests { #[inline(always)] fn is_method_call(&self) -> bool { true } #[inline(always)] fn is_variadic(&self) -> bool { false } - #[inline(always)] fn clone_boxed(&self) -> Box { - Box::new(set_by_index_token()) - } - #[inline(always)] fn param_names(&self) -> Box<[&'static str]> { - new_vec!["x: &mut MyCollection", "i: u64", "item: FLOAT", "()"].into_boxed_slice() - } - #[inline(always)] fn input_types(&self) -> Box<[TypeId]> { - new_vec![TypeId::of::(), - TypeId::of::(), - TypeId::of::()].into_boxed_slice() - } - } - #[inline(always)] pub fn set_by_index_token_callable() -> CallableFunction { - set_by_index_token().into() - } - #[inline(always)] pub fn set_by_index_token_param_names() -> Box<[&'static str]> { - set_by_index_token().param_names() - } - #[inline(always)] pub fn set_by_index_token_input_types() -> Box<[TypeId]> { - set_by_index_token().input_types() } } }; diff --git a/codegen/ui_tests/rhai_mod_unknown_type.stderr b/codegen/ui_tests/rhai_mod_unknown_type.stderr index 1b400234..5f61d9d3 100644 --- a/codegen/ui_tests/rhai_mod_unknown_type.stderr +++ b/codegen/ui_tests/rhai_mod_unknown_type.stderr @@ -15,7 +15,7 @@ help: consider importing one of these items | 11 | use core::fmt::Pointer; | -11 | use crate::new_vec::fmt::Pointer; +11 | use crate::mem::fmt::Pointer; | 11 | use std::fmt::Pointer; | diff --git a/src/plugin.rs b/src/plugin.rs index 4a890af6..9ea4bb10 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,7 +1,7 @@ //! Module defining macros for developing _plugins_. pub use crate::fn_native::{CallableFunction, FnCallArgs}; -pub use crate::stdlib::{any::TypeId, boxed::Box, format, mem, string::ToString, vec as new_vec}; +pub use crate::stdlib::{any::TypeId, boxed::Box, format, mem, string::ToString}; pub use crate::{ Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module, NativeCallContext, Position, @@ -26,13 +26,4 @@ pub trait PluginFunction { /// Is this plugin function variadic? fn is_variadic(&self) -> bool; - - /// Convert a plugin function into a boxed trait object. - fn clone_boxed(&self) -> Box; - - /// Return a boxed slice of the names of the function's parameters and return type. - fn param_names(&self) -> Box<[&'static str]>; - - /// Return a boxed slice of type ID's of the function's parameters. - fn input_types(&self) -> Box<[TypeId]>; }