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]
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
/// the same time so that the total _size_ of the [`Scope`][crate::Scope] is unchanged) also
/// 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,
symbols: &[S],
symbols: &[impl AsRef<str> + Into<Identifier>],
scope_may_be_changed: bool,
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
) -> 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| {
let x = args[0].$xx().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| {
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| {
let x = <$base>::from(args[0].$xx().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()
.map_err(|typ| self.make_type_mismatch_err::<ImmutableString>(typ, arg_pos))
.and_then(FnPtr::try_from)
.map(Into::<Dynamic>::into)
.map(Into::into)
.map_err(|err| err.fill_position(arg_pos));
}

View File

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

View File

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

View File

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