use crate::alloc::{Allocator, Global};
use crate::clone::TryClone;
use crate::error::Error;
use crate::iter::{TryCloned, TryFromIteratorIn, TryJoin};
pub trait IteratorExt: Iterator + self::sealed::Sealed {
fn try_collect<B>(self) -> Result<B, Error>
where
Self: Sized,
B: TryFromIteratorIn<Self::Item, Global>,
{
self.try_collect_in(Global)
}
fn try_collect_in<B, A: Allocator>(self, alloc: A) -> Result<B, Error>
where
Self: Sized,
B: TryFromIteratorIn<Self::Item, A>,
{
TryFromIteratorIn::try_from_iter_in(self, alloc)
}
fn try_join<J, S>(self, sep: S) -> Result<J, Error>
where
Self: Sized,
J: TryJoin<S, Self::Item, Global>,
{
J::try_join_in(self, sep, Global)
}
fn try_join_in<J, S, A: Allocator>(self, sep: S, alloc: A) -> Result<J, Error>
where
Self: Sized,
J: TryJoin<S, Self::Item, A>,
{
J::try_join_in(self, sep, alloc)
}
fn try_cloned<'a, T>(self) -> TryCloned<Self>
where
Self: Sized + Iterator<Item = &'a T>,
T: 'a + TryClone,
{
TryCloned::new(self)
}
}
impl<I> IteratorExt for I where I: Iterator {}
mod sealed {
pub trait Sealed {}
impl<I> Sealed for I where I: Iterator {}
}