Reduce feature gates on imports.

This commit is contained in:
Stephen Chung
2020-11-16 16:28:04 +08:00
parent ef02150afd
commit adb902326e
20 changed files with 206 additions and 292 deletions

View File

@@ -8,9 +8,6 @@ use crate::utils::ImmutableString;
use crate::StaticVec;
use crate::INT;
#[cfg(not(feature = "unchecked"))]
use crate::{result::EvalAltResult, token::NO_POS};
use crate::stdlib::{
any::TypeId, boxed::Box, format, mem, string::String, string::ToString, vec::Vec,
};
@@ -255,11 +252,15 @@ mod string_functions {
s: &mut ImmutableString,
len: INT,
ch: char,
) -> Result<Dynamic, Box<EvalAltResult>> {
) -> Result<Dynamic, Box<crate::EvalAltResult>> {
// Check if string will be over max size limit
#[cfg(not(feature = "unchecked"))]
if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() {
return EvalAltResult::ErrorDataTooLarge("Length of string".to_string(), NO_POS).into();
return crate::EvalAltResult::ErrorDataTooLarge(
"Length of string".to_string(),
crate::NO_POS,
)
.into();
}
if len > 0 {
@@ -275,9 +276,9 @@ mod string_functions {
#[cfg(not(feature = "unchecked"))]
if _ctx.engine().max_string_size() > 0 && s.len() > _ctx.engine().max_string_size()
{
return EvalAltResult::ErrorDataTooLarge(
return crate::EvalAltResult::ErrorDataTooLarge(
"Length of string".to_string(),
NO_POS,
crate::NO_POS,
)
.into();
}
@@ -292,11 +293,15 @@ mod string_functions {
s: &mut ImmutableString,
len: INT,
padding: &str,
) -> Result<Dynamic, Box<EvalAltResult>> {
) -> Result<Dynamic, Box<crate::EvalAltResult>> {
// Check if string will be over max size limit
#[cfg(not(feature = "unchecked"))]
if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() {
return EvalAltResult::ErrorDataTooLarge("Length of string".to_string(), NO_POS).into();
return crate::EvalAltResult::ErrorDataTooLarge(
"Length of string".to_string(),
crate::NO_POS,
)
.into();
}
if len > 0 {
@@ -319,9 +324,9 @@ mod string_functions {
#[cfg(not(feature = "unchecked"))]
if _ctx.engine().max_string_size() > 0 && s.len() > _ctx.engine().max_string_size()
{
return EvalAltResult::ErrorDataTooLarge(
return crate::EvalAltResult::ErrorDataTooLarge(
"Length of string".to_string(),
NO_POS,
crate::NO_POS,
)
.into();
}
@@ -333,7 +338,7 @@ mod string_functions {
#[cfg(not(feature = "no_index"))]
pub mod arrays {
use crate::engine::Array;
use crate::Array;
#[rhai_fn(name = "+")]
pub fn append(x: &str, y: Array) -> String {
@@ -356,7 +361,7 @@ mod string_functions {
#[cfg(not(feature = "no_object"))]
pub mod maps {
use crate::engine::Map;
use crate::Map;
#[rhai_fn(name = "+")]
pub fn append(x: &str, y: Map) -> String {