Fully feature gate array string functions

This commit is contained in:
J Henry Waugh 2020-08-14 16:49:24 -05:00
parent 4de02c2bd7
commit e6a1b88b4c

View File

@ -44,8 +44,6 @@ macro_rules! reg_functions {
def_package!(crate:MoreStringPackage:"Additional string utilities, including string building.", lib, { def_package!(crate:MoreStringPackage:"Additional string utilities, including string building.", lib, {
reg_functions!(lib += basic; INT, bool, char, FnPtr); reg_functions!(lib += basic; INT, bool, char, FnPtr);
set_exported_fn!(lib, "+", string_funcs::append_unit);
set_exported_fn!(lib, "+", string_funcs::prepend_unit);
#[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))] #[cfg(not(feature = "only_i64"))]
@ -61,8 +59,8 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
{ {
set_exported_fn!(lib, "+", string_funcs::append_array); set_exported_fn!(lib, "+", string_funcs_array::append_array);
set_exported_fn!(lib, "+", string_funcs::prepend_array); set_exported_fn!(lib, "+", string_funcs_array::prepend_array);
} }
lib.combine(exported_module!(string_functions)); lib.combine(exported_module!(string_functions));
@ -189,8 +187,23 @@ mod string_functions {
} }
} }
mod string_funcs { #[cfg(not(feature = "no_index"))]
mod string_funcs_array {
use crate::engine::Array; use crate::engine::Array;
use crate::plugin::*;
use crate::utils::ImmutableString;
#[export_fn]
pub fn append_array(x: &mut ImmutableString, y: Array) -> String {
format!("{}{:?}", x, y)
}
#[export_fn]
pub fn prepend_array(x: &mut Array, y: ImmutableString) -> String {
format!("{:?}{}", x, y)
}
}
mod string_funcs {
use crate::parser::INT; use crate::parser::INT;
use crate::plugin::*; use crate::plugin::*;
use crate::utils::{ImmutableString, StaticVec}; use crate::utils::{ImmutableString, StaticVec};
@ -204,14 +217,6 @@ mod string_funcs {
s s
} }
#[export_fn] #[export_fn]
pub fn append_array(x: &mut ImmutableString, y: Array) -> String {
format!("{}{:?}", x, y)
}
#[export_fn]
pub fn prepend_array(x: &mut Array, y: ImmutableString) -> String {
format!("{:?}{}", x, y)
}
#[export_fn]
pub fn len(s: &mut ImmutableString) -> INT { pub fn len(s: &mut ImmutableString) -> INT {
s.chars().count() as INT s.chars().count() as INT
} }