No need for types with Into::into.

This commit is contained in:
Stephen Chung 2021-12-27 16:59:05 +08:00
parent f443e4d9f6
commit 757eacfdde
7 changed files with 17 additions and 35 deletions

View File

@ -286,7 +286,7 @@ impl<F: Float + FromStr> FromStr for FloatWrapper<F> {
#[inline] #[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
F::from_str(s).map(Into::<Self>::into) F::from_str(s).map(Into::into)
} }
} }

View File

@ -211,9 +211,9 @@ impl Engine {
/// Replacing one variable with another (i.e. adding a new variable and removing one variable at /// Replacing one variable with another (i.e. adding a new variable and removing one variable at
/// the same time so that the total _size_ of the [`Scope`][crate::Scope] is unchanged) also /// the same time so that the total _size_ of the [`Scope`][crate::Scope] is unchanged) also
/// does NOT count, so `false` should be passed. /// does NOT count, so `false` should be passed.
pub fn register_custom_syntax<S: AsRef<str> + Into<Identifier>>( pub fn register_custom_syntax(
&mut self, &mut self,
symbols: &[S], symbols: &[impl AsRef<str> + Into<Identifier>],
scope_may_be_changed: bool, scope_may_be_changed: bool,
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static, func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
) -> ParseResult<&mut Self> { ) -> ParseResult<&mut Self> {

View File

@ -89,7 +89,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
($base:ty => $func:ident ( $xx:ident, $yy:ident )) => { |_, args| { ($base:ty => $func:ident ( $xx:ident, $yy:ident )) => { |_, args| {
let x = args[0].$xx().expect(BUILTIN) as $base; let x = args[0].$xx().expect(BUILTIN) as $base;
let y = args[1].$yy().expect(BUILTIN) as $base; let y = args[1].$yy().expect(BUILTIN) as $base;
$func(x, y).map(Into::<Dynamic>::into) $func(x, y).map(Into::into)
} }; } };
(from $base:ty => $xx:ident $op:tt $yy:ident) => { |_, args| { (from $base:ty => $xx:ident $op:tt $yy:ident) => { |_, args| {
let x = <$base>::from(args[0].$xx().expect(BUILTIN)); let x = <$base>::from(args[0].$xx().expect(BUILTIN));
@ -104,7 +104,7 @@ pub fn get_builtin_binary_op_fn(op: &str, x: &Dynamic, y: &Dynamic) -> Option<Fn
(from $base:ty => $func:ident ( $xx:ident, $yy:ident )) => { |_, args| { (from $base:ty => $func:ident ( $xx:ident, $yy:ident )) => { |_, args| {
let x = <$base>::from(args[0].$xx().expect(BUILTIN)); let x = <$base>::from(args[0].$xx().expect(BUILTIN));
let y = <$base>::from(args[1].$yy().expect(BUILTIN)); let y = <$base>::from(args[1].$yy().expect(BUILTIN));
$func(x, y).map(Into::<Dynamic>::into) $func(x, y).map(Into::into)
} }; } };
} }

View File

@ -967,7 +967,7 @@ impl Engine {
.into_immutable_string() .into_immutable_string()
.map_err(|typ| self.make_type_mismatch_err::<ImmutableString>(typ, arg_pos)) .map_err(|typ| self.make_type_mismatch_err::<ImmutableString>(typ, arg_pos))
.and_then(FnPtr::try_from) .and_then(FnPtr::try_from)
.map(Into::<Dynamic>::into) .map(Into::into)
.map_err(|err| err.fill_position(arg_pos)); .map_err(|err| err.fill_position(arg_pos));
} }

View File

@ -71,7 +71,7 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
f.params f.params
.iter() .iter()
.cloned() .cloned()
.map(Into::<Dynamic>::into) .map(Into::into)
.collect::<Array>() .collect::<Array>()
.into(), .into(),
); );

View File

@ -102,7 +102,7 @@ mod map_functions {
if map.is_empty() { if map.is_empty() {
Array::new() Array::new()
} else { } else {
map.keys().cloned().map(Into::<Dynamic>::into).collect() map.keys().cloned().map(Into::into).collect()
} }
} }
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]

View File

@ -599,7 +599,7 @@ mod string_functions {
if string.is_empty() { if string.is_empty() {
Array::new() Array::new()
} else { } else {
string.chars().map(Into::<Dynamic>::into).collect() string.chars().map(Into::into).collect()
} }
} }
#[rhai_fn(name = "split")] #[rhai_fn(name = "split")]
@ -624,57 +624,39 @@ mod string_functions {
} }
} }
pub fn split(string: &str, delimiter: &str) -> Array { pub fn split(string: &str, delimiter: &str) -> Array {
string.split(delimiter).map(Into::<Dynamic>::into).collect() string.split(delimiter).map(Into::into).collect()
} }
#[rhai_fn(name = "split")] #[rhai_fn(name = "split")]
pub fn splitn(string: &str, delimiter: &str, segments: INT) -> Array { pub fn splitn(string: &str, delimiter: &str, segments: INT) -> Array {
let pieces: usize = if segments < 1 { 1 } else { segments as usize }; let pieces: usize = if segments < 1 { 1 } else { segments as usize };
string string.splitn(pieces, delimiter).map(Into::into).collect()
.splitn(pieces, delimiter)
.map(Into::<Dynamic>::into)
.collect()
} }
#[rhai_fn(name = "split")] #[rhai_fn(name = "split")]
pub fn split_char(string: &str, delimiter: char) -> Array { pub fn split_char(string: &str, delimiter: char) -> Array {
string.split(delimiter).map(Into::<Dynamic>::into).collect() string.split(delimiter).map(Into::into).collect()
} }
#[rhai_fn(name = "split")] #[rhai_fn(name = "split")]
pub fn splitn_char(string: &str, delimiter: char, segments: INT) -> Array { pub fn splitn_char(string: &str, delimiter: char, segments: INT) -> Array {
let pieces: usize = if segments < 1 { 1 } else { segments as usize }; let pieces: usize = if segments < 1 { 1 } else { segments as usize };
string string.splitn(pieces, delimiter).map(Into::into).collect()
.splitn(pieces, delimiter)
.map(Into::<Dynamic>::into)
.collect()
} }
#[rhai_fn(name = "split_rev")] #[rhai_fn(name = "split_rev")]
pub fn rsplit(string: &str, delimiter: &str) -> Array { pub fn rsplit(string: &str, delimiter: &str) -> Array {
string string.rsplit(delimiter).map(Into::into).collect()
.rsplit(delimiter)
.map(Into::<Dynamic>::into)
.collect()
} }
#[rhai_fn(name = "split_rev")] #[rhai_fn(name = "split_rev")]
pub fn rsplitn(string: &str, delimiter: &str, segments: INT) -> Array { pub fn rsplitn(string: &str, delimiter: &str, segments: INT) -> Array {
let pieces: usize = if segments < 1 { 1 } else { segments as usize }; let pieces: usize = if segments < 1 { 1 } else { segments as usize };
string string.rsplitn(pieces, delimiter).map(Into::into).collect()
.rsplitn(pieces, delimiter)
.map(Into::<Dynamic>::into)
.collect()
} }
#[rhai_fn(name = "split_rev")] #[rhai_fn(name = "split_rev")]
pub fn rsplit_char(string: &str, delimiter: char) -> Array { pub fn rsplit_char(string: &str, delimiter: char) -> Array {
string string.rsplit(delimiter).map(Into::into).collect()
.rsplit(delimiter)
.map(Into::<Dynamic>::into)
.collect()
} }
#[rhai_fn(name = "split_rev")] #[rhai_fn(name = "split_rev")]
pub fn rsplitn_char(string: &str, delimiter: char, segments: INT) -> Array { pub fn rsplitn_char(string: &str, delimiter: char, segments: INT) -> Array {
let pieces: usize = if segments < 1 { 1 } else { segments as usize }; let pieces: usize = if segments < 1 { 1 } else { segments as usize };
string string.rsplitn(pieces, delimiter).map(Into::into).collect()
.rsplitn(pieces, delimiter)
.map(Into::<Dynamic>::into)
.collect()
} }
} }
} }