Reduce nesting in plugin sub-modules.
This commit is contained in:
parent
ae493918a2
commit
313999b0ac
@ -15,21 +15,17 @@ mod fn_ptr_functions {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub mod functions {
|
||||
#[rhai_fn(name = "is_anonymous", get = "is_anonymous", pure)]
|
||||
pub fn is_anonymous(fn_ptr: &mut FnPtr) -> bool {
|
||||
fn_ptr.is_anonymous()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
pub mod functions_and_maps {
|
||||
pub fn get_fn_metadata_list(ctx: NativeCallContext) -> crate::Array {
|
||||
collect_fn_metadata(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
|
@ -108,7 +108,6 @@ mod map_functions {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
pub mod indexing {
|
||||
#[rhai_fn(pure)]
|
||||
pub fn keys(map: &mut Map) -> Array {
|
||||
if map.is_empty() {
|
||||
@ -117,6 +116,7 @@ mod map_functions {
|
||||
map.keys().cloned().map(Into::<Dynamic>::into).collect()
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
#[rhai_fn(pure)]
|
||||
pub fn values(map: &mut Map) -> Array {
|
||||
if map.is_empty() {
|
||||
@ -125,5 +125,4 @@ mod map_functions {
|
||||
map.values().cloned().collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,12 +293,10 @@ mod float_functions {
|
||||
})
|
||||
}
|
||||
#[cfg(not(feature = "f32_float"))]
|
||||
pub mod f32_f64 {
|
||||
#[rhai_fn(name = "to_float")]
|
||||
pub fn f32_to_f64(x: f32) -> f64 {
|
||||
x as f64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "decimal")]
|
||||
@ -308,22 +306,24 @@ mod decimal_functions {
|
||||
prelude::{FromStr, RoundingStrategy},
|
||||
Decimal, MathematicalOps,
|
||||
};
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[cfg(feature = "no_float")]
|
||||
pub mod float_polyfills {
|
||||
#[rhai_fn(name = "PI")]
|
||||
pub fn pi() -> Decimal {
|
||||
Decimal::PI
|
||||
}
|
||||
#[cfg(feature = "no_float")]
|
||||
#[rhai_fn(name = "E")]
|
||||
pub fn e() -> Decimal {
|
||||
Decimal::E
|
||||
}
|
||||
#[cfg(feature = "no_float")]
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn parse_float(s: &str) -> Result<Decimal, Box<EvalAltResult>> {
|
||||
super::parse_decimal(s)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sin(x: Decimal) -> Decimal {
|
||||
x.sin()
|
||||
@ -480,9 +480,6 @@ mod decimal_functions {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
pub mod float {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[rhai_fn(name = "to_decimal", return_raw)]
|
||||
pub fn f32_to_decimal(x: f32) -> Result<Decimal, Box<EvalAltResult>> {
|
||||
Decimal::try_from(x).map_err(|_| {
|
||||
@ -493,6 +490,7 @@ mod decimal_functions {
|
||||
.into()
|
||||
})
|
||||
}
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[rhai_fn(name = "to_decimal", return_raw)]
|
||||
pub fn f64_to_decimal(x: f64) -> Result<Decimal, Box<EvalAltResult>> {
|
||||
Decimal::try_from(x).map_err(|_| {
|
||||
@ -503,6 +501,7 @@ mod decimal_functions {
|
||||
.into()
|
||||
})
|
||||
}
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn to_float(x: Decimal) -> Result<FLOAT, Box<EvalAltResult>> {
|
||||
FLOAT::try_from(x).map_err(|_| {
|
||||
@ -513,7 +512,6 @@ mod decimal_functions {
|
||||
.into()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
|
@ -71,31 +71,27 @@ mod print_debug_functions {
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
pub mod float_functions {
|
||||
use crate::ast::FloatWrapper;
|
||||
|
||||
#[rhai_fn(name = "print", name = "to_string")]
|
||||
pub fn print_f64(number: f64) -> ImmutableString {
|
||||
FloatWrapper::new(number).to_string().into()
|
||||
crate::ast::FloatWrapper::new(number).to_string().into()
|
||||
}
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[rhai_fn(name = "print", name = "to_string")]
|
||||
pub fn print_f32(number: f32) -> ImmutableString {
|
||||
FloatWrapper::new(number).to_string().into()
|
||||
crate::ast::FloatWrapper::new(number).to_string().into()
|
||||
}
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[rhai_fn(name = "debug", name = "to_debug")]
|
||||
pub fn debug_f64(number: f64) -> ImmutableString {
|
||||
format!("{:?}", FloatWrapper::new(number)).into()
|
||||
format!("{:?}", crate::ast::FloatWrapper::new(number)).into()
|
||||
}
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
#[rhai_fn(name = "debug", name = "to_debug")]
|
||||
pub fn debug_f32(number: f32) -> ImmutableString {
|
||||
format!("{:?}", FloatWrapper::new(number)).into()
|
||||
}
|
||||
format!("{:?}", crate::ast::FloatWrapper::new(number)).into()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
pub mod array_functions {
|
||||
use super::*;
|
||||
|
||||
#[rhai_fn(
|
||||
name = "print",
|
||||
name = "to_string",
|
||||
@ -118,11 +114,7 @@ mod print_debug_functions {
|
||||
result.push(']');
|
||||
result.into()
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
pub mod map_functions {
|
||||
use super::*;
|
||||
|
||||
#[rhai_fn(
|
||||
name = "print",
|
||||
name = "to_string",
|
||||
@ -147,7 +139,6 @@ mod print_debug_functions {
|
||||
result.push('}');
|
||||
result.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[export_module]
|
||||
|
Loading…
Reference in New Issue
Block a user