Satisfy clippy.
This commit is contained in:
@@ -155,7 +155,7 @@ mod array_functions {
|
||||
len as usize
|
||||
};
|
||||
|
||||
array[start..start + len].iter().cloned().collect()
|
||||
array[start..start + len].to_vec()
|
||||
}
|
||||
#[rhai_fn(name = "extract")]
|
||||
pub fn extract_tail(array: &mut Array, start: INT) -> Array {
|
||||
@@ -170,7 +170,7 @@ mod array_functions {
|
||||
start as usize
|
||||
};
|
||||
|
||||
array[start..].iter().cloned().collect()
|
||||
array[start..].to_vec()
|
||||
}
|
||||
#[rhai_fn(name = "split")]
|
||||
pub fn split_at(array: &mut Array, start: INT) -> Array {
|
||||
|
@@ -50,14 +50,11 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
|
||||
let mut map = Map::new();
|
||||
|
||||
if let Some(ns) = namespace {
|
||||
map.insert(dict.get("namespace").expect(DICT).clone().into(), ns.into());
|
||||
map.insert(dict.get("namespace").expect(DICT).clone(), ns.into());
|
||||
}
|
||||
map.insert(dict.get("name").expect(DICT).clone(), f.name.clone().into());
|
||||
map.insert(
|
||||
dict.get("name").expect(DICT).clone().into(),
|
||||
f.name.clone().into(),
|
||||
);
|
||||
map.insert(
|
||||
dict.get("access").expect(DICT).clone().into(),
|
||||
dict.get("access").expect(DICT).clone(),
|
||||
match f.access {
|
||||
FnAccess::Public => dict.get("public").expect(DICT).clone(),
|
||||
FnAccess::Private => dict.get("private").expect(DICT).clone(),
|
||||
@@ -65,11 +62,11 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
|
||||
.into(),
|
||||
);
|
||||
map.insert(
|
||||
dict.get("is_anonymous").expect(DICT).clone().into(),
|
||||
dict.get("is_anonymous").expect(DICT).clone(),
|
||||
f.name.starts_with(crate::engine::FN_ANONYMOUS).into(),
|
||||
);
|
||||
map.insert(
|
||||
dict.get("params").expect(DICT).clone().into(),
|
||||
dict.get("params").expect(DICT).clone(),
|
||||
f.params
|
||||
.iter()
|
||||
.cloned()
|
||||
@@ -78,7 +75,7 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
|
||||
.into(),
|
||||
);
|
||||
|
||||
map.into()
|
||||
map
|
||||
}
|
||||
|
||||
// Intern strings
|
||||
|
@@ -54,31 +54,19 @@ where
|
||||
None
|
||||
} else if self.0 < self.1 {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
let diff1 = if let Some(diff) = self.1.checked_sub(&self.0) {
|
||||
diff
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let diff1 = self.1.checked_sub(&self.0)?;
|
||||
#[cfg(feature = "unchecked")]
|
||||
let diff1 = self.1 - self.0;
|
||||
|
||||
let v = self.0;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
let n = if let Some(num) = self.0.checked_add(&self.2) {
|
||||
num
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let n = self.0.checked_add(&self.2)?;
|
||||
#[cfg(feature = "unchecked")]
|
||||
let n = self.0 + self.2;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
let diff2 = if let Some(diff) = self.1.checked_sub(&n) {
|
||||
diff
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let diff2 = self.1.checked_sub(&n)?;
|
||||
#[cfg(feature = "unchecked")]
|
||||
let diff2 = self.1 - n;
|
||||
|
||||
@@ -90,31 +78,19 @@ where
|
||||
}
|
||||
} else {
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
let diff1 = if let Some(diff) = self.0.checked_sub(&self.1) {
|
||||
diff
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let diff1 = self.0.checked_sub(&self.1)?;
|
||||
#[cfg(feature = "unchecked")]
|
||||
let diff1 = self.0 - self.1;
|
||||
|
||||
let v = self.0;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
let n = if let Some(num) = self.0.checked_add(&self.2) {
|
||||
num
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let n = self.0.checked_add(&self.2)?;
|
||||
#[cfg(feature = "unchecked")]
|
||||
let n = self.0 + self.2;
|
||||
|
||||
#[cfg(not(feature = "unchecked"))]
|
||||
let diff2 = if let Some(diff) = n.checked_sub(&self.1) {
|
||||
diff
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let diff2 = n.checked_sub(&self.1)?;
|
||||
#[cfg(feature = "unchecked")]
|
||||
let diff2 = n - self.1;
|
||||
|
||||
@@ -395,7 +371,7 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
||||
|
||||
lib.set_iterator::<StepFloatRange>();
|
||||
|
||||
let _hash = lib.set_native_fn("range", |from, to, step| StepFloatRange::new(from, to, step));
|
||||
let _hash = lib.set_native_fn("range", StepFloatRange::new);
|
||||
#[cfg(feature = "metadata")]
|
||||
lib.update_fn_metadata(_hash, &["from: FLOAT", "to: FLOAT", "step: FLOAT", "Iterator<Item=FLOAT>"]);
|
||||
}
|
||||
@@ -457,7 +433,7 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
||||
|
||||
lib.set_iterator::<StepDecimalRange>();
|
||||
|
||||
let _hash = lib.set_native_fn("range", |from, to, step| StepDecimalRange::new(from, to, step));
|
||||
let _hash = lib.set_native_fn("range", StepDecimalRange::new);
|
||||
#[cfg(feature = "metadata")]
|
||||
lib.update_fn_metadata(_hash, &["from: Decimal", "to: Decimal", "step: Decimal", "Iterator<Item=Decimal>"]);
|
||||
}
|
||||
@@ -465,7 +441,7 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
||||
// Register string iterator
|
||||
lib.set_iterator::<CharsStream>();
|
||||
|
||||
let _hash = lib.set_native_fn("chars", |string, from,len| Ok(CharsStream::new(string, from, len)));
|
||||
let _hash = lib.set_native_fn("chars", |string, from, len| Ok(CharsStream::new(string, from, len)));
|
||||
#[cfg(feature = "metadata")]
|
||||
lib.update_fn_metadata(_hash, &["string: &str", "from: INT", "len: INT", "Iterator<Item=char>"]);
|
||||
|
||||
@@ -480,7 +456,7 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
||||
// Register bit-field iterator
|
||||
lib.set_iterator::<BitRange>();
|
||||
|
||||
let _hash = lib.set_native_fn("bits", |value, from, len| BitRange::new(value, from, len));
|
||||
let _hash = lib.set_native_fn("bits", BitRange::new);
|
||||
#[cfg(feature = "metadata")]
|
||||
lib.update_fn_metadata(_hash, &["value: INT", "from: INT", "len: INT", "Iterator<Item=bool>"]);
|
||||
|
||||
|
@@ -113,7 +113,7 @@ def_package!(crate:BasicMathPackage:"Basic mathematic functions.", lib, {
|
||||
mod int_functions {
|
||||
#[rhai_fn(name = "parse_int", return_raw)]
|
||||
pub fn parse_int_radix(s: &str, radix: INT) -> Result<INT, Box<EvalAltResult>> {
|
||||
if radix < 2 || radix > 36 {
|
||||
if !(2..=36).contains(&radix) {
|
||||
return EvalAltResult::ErrorArithmetic(
|
||||
format!("Invalid radix: '{}'", radix),
|
||||
Position::NONE,
|
||||
|
@@ -79,8 +79,13 @@ macro_rules! def_package {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for $package {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl $package {
|
||||
#[allow(dead_code)]
|
||||
pub fn new() -> Self {
|
||||
let mut module = $root::Module::new();
|
||||
<Self as $root::packages::Package>::init(&mut module);
|
||||
|
@@ -12,8 +12,8 @@ use crate::Array;
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
use crate::Map;
|
||||
|
||||
pub const FUNC_TO_STRING: &'static str = "to_string";
|
||||
pub const FUNC_TO_DEBUG: &'static str = "to_debug";
|
||||
pub const FUNC_TO_STRING: &str = "to_string";
|
||||
pub const FUNC_TO_DEBUG: &str = "to_debug";
|
||||
|
||||
def_package!(crate:BasicStringPackage:"Basic string utilities, including printing.", lib, {
|
||||
combine_with_exported_module!(lib, "print_debug", print_debug_functions);
|
||||
@@ -106,7 +106,7 @@ mod print_debug_functions {
|
||||
pub fn format_array(ctx: NativeCallContext, array: &mut Array) -> ImmutableString {
|
||||
let len = array.len();
|
||||
let mut result = String::with_capacity(len * 5 + 2);
|
||||
result.push_str("[");
|
||||
result.push('[');
|
||||
|
||||
array.iter_mut().enumerate().for_each(|(i, x)| {
|
||||
result.push_str(&print_with_func(FUNC_TO_DEBUG, &ctx, x));
|
||||
@@ -115,7 +115,7 @@ mod print_debug_functions {
|
||||
}
|
||||
});
|
||||
|
||||
result.push_str("]");
|
||||
result.push(']');
|
||||
result.into()
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ mod print_debug_functions {
|
||||
));
|
||||
});
|
||||
|
||||
result.push_str("}");
|
||||
result.push('}');
|
||||
result.into()
|
||||
}
|
||||
}
|
||||
|
@@ -38,12 +38,11 @@ mod string_functions {
|
||||
) -> ImmutableString {
|
||||
let mut s = print_with_func(FUNC_TO_STRING, &ctx, item);
|
||||
|
||||
if string.is_empty() {
|
||||
s
|
||||
} else {
|
||||
if !string.is_empty() {
|
||||
s.make_mut().push_str(string);
|
||||
s.into()
|
||||
}
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
#[rhai_fn(name = "+", name = "append")]
|
||||
@@ -240,7 +239,7 @@ mod string_functions {
|
||||
let mut chars = StaticVec::with_capacity(string.len());
|
||||
|
||||
let offset = if string.is_empty() || len <= 0 {
|
||||
return ctx.engine().empty_string.clone().into();
|
||||
return ctx.engine().empty_string.clone();
|
||||
} else if start < 0 {
|
||||
if let Some(n) = start.checked_abs() {
|
||||
chars.extend(string.chars());
|
||||
@@ -253,7 +252,7 @@ mod string_functions {
|
||||
0
|
||||
}
|
||||
} else if start as usize >= string.chars().count() {
|
||||
return ctx.engine().empty_string.clone().into();
|
||||
return ctx.engine().empty_string.clone();
|
||||
} else {
|
||||
start as usize
|
||||
};
|
||||
|
Reference in New Issue
Block a user