Simplify iterator registration.

This commit is contained in:
Stephen Chung
2020-10-15 22:11:18 +08:00
parent ea9ef1091a
commit 3b99b8f166
5 changed files with 27 additions and 36 deletions

View File

@@ -1469,18 +1469,22 @@ impl Module {
}
/// Set a type iterator into the module.
pub fn set_iterable<T: Variant + Clone + IntoIterator<Item = U>, U: Variant + Clone>(
&mut self,
) -> &mut Self {
pub fn set_iterable<T>(&mut self) -> &mut Self
where
T: Variant + Clone + IntoIterator,
<T as IntoIterator>::Item: Variant + Clone,
{
self.set_iter(TypeId::of::<T>(), |obj: Dynamic| {
Box::new(obj.cast::<T>().into_iter().map(Dynamic::from))
})
}
/// Set an iterator type into the module as a type iterator.
pub fn set_iterator<T: Variant + Clone + Iterator<Item = U>, U: Variant + Clone>(
&mut self,
) -> &mut Self {
pub fn set_iterator<T>(&mut self) -> &mut Self
where
T: Variant + Clone + Iterator,
<T as Iterator>::Item: Variant + Clone,
{
self.set_iter(TypeId::of::<T>(), |obj: Dynamic| {
Box::new(obj.cast::<T>().map(Dynamic::from))
})