use std::iter::FusedIterator; use std::collections::BTreeSet; use std::borrow::Borrow; use futures::prelude::*; mod iters; pub use iters::*; mod streams; pub use streams::*; mod hashers; pub use hashers::*; pub const PRECOLLECT_STACK_SIZE: usize = 64; /// Collect an iterator's output and then drop it to detach the iterator from any references or resources it might have. #[macro_export] macro_rules! precollect { ($iter:expr, $num:literal) => { { { let it: ::smallvec::SmallVec<[_; $num]> = $iter.into_iter().collect(); it.into_iter() } } }; ($iter:expr) => { { { let it: ::smallvec::SmallVec<[_; $crate::ext::PRECOLLECT_STACK_SIZE]> = $iter.into_iter().collect(); it.into_iter() } } } } #[macro_export] macro_rules! no_op { ($expr:expr) => { { $expr; } }; } #[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)] pub enum Either { T(T), U(U), } impl Either { /// Convert this sum type into pub fn cast(self) -> V where V: From + From// eh, this doesn't work. forget about it. { match self { Self::T(t) => t.into(), Self::U(u) => u.into(), } } } /// Create an ad-hoc sum type. macro_rules! either { (@ type $first:ty) => { $first }; (@ type $first:ty, $($rest:ty),*) => { Either<$first, either!(@ type $($rest),*)> }; (type $($type:ty)|*) => { either!(@ type $($type),*) }; }