Files
orchid/src/utils/boxed_iter.rs
Lawrence Bethlenfalvy 3c0056c2db Generic mutation scheduling system
IO adapted to use it
Also, Atoms can now dispatch type-erased requests
2023-09-14 22:54:42 +01:00

28 lines
816 B
Rust

/// Utility functions to get rid of tedious explicit casts to
/// BoxedIter
use std::iter;
/// A trait object of [Iterator] to be assigned to variables that may be
/// initialized form multiple iterators of incompatible types
pub type BoxedIter<'a, T> = Box<dyn Iterator<Item = T> + 'a>;
/// creates a [BoxedIter] of a single element
pub fn box_once<'a, T: 'a>(t: T) -> BoxedIter<'a, T> {
Box::new(iter::once(t))
}
/// creates an empty [BoxedIter]
pub fn box_empty<'a, T: 'a>() -> BoxedIter<'a, T> {
Box::new(iter::empty())
}
/// Chain various iterators into a [BoxedIter]
macro_rules! box_chain {
($curr:expr) => {
Box::new($curr) as BoxedIter<_>
};
($curr:expr, $($rest:expr),*) => {
Box::new($curr$(.chain($rest))*) as $crate::utils::boxed_iter::BoxedIter<_>
};
}
pub(crate) use box_chain;