You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.4 KiB

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,U>
{
T(T),
U(U),
}
impl<T,U> Either<T,U>
{
/// Convert this sum type into
pub fn cast<V>(self) -> V
where V: From<T> + From<U>// 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),*)
};
}