Avoid copying iterator sources.

This commit is contained in:
Stephen Chung
2020-04-24 22:54:56 +08:00
parent 3cb3dc8e4f
commit 9998cf8890
4 changed files with 16 additions and 27 deletions

View File

@@ -19,14 +19,9 @@ where
{
lib.type_iterators.insert(
TypeId::of::<Range<T>>(),
Box::new(|source: &Dynamic| {
Box::new(
source
.downcast_ref::<Range<T>>()
.cloned()
.unwrap()
.map(|x| x.into_dynamic()),
) as Box<dyn Iterator<Item = Dynamic>>
Box::new(|source: Dynamic| {
Box::new(source.cast::<Range<T>>().map(|x| x.into_dynamic()))
as Box<dyn Iterator<Item = Dynamic>>
}),
);
}
@@ -64,14 +59,9 @@ where
{
lib.type_iterators.insert(
TypeId::of::<StepRange<T>>(),
Box::new(|source: &Dynamic| {
Box::new(
source
.downcast_ref::<StepRange<T>>()
.cloned()
.unwrap()
.map(|x| x.into_dynamic()),
) as Box<dyn Iterator<Item = Dynamic>>
Box::new(|source: Dynamic| {
Box::new(source.cast::<StepRange<T>>().map(|x| x.into_dynamic()))
as Box<dyn Iterator<Item = Dynamic>>
}),
);
}