use crate::FallibleVec;
use crate::TryReserveError;
use alloc::vec::Vec;
#[cfg(feature = "allocator_api")]
use core::alloc::Allocator;
pub trait TryCollect<T> {
#[cfg(feature = "allocator_api")]
fn try_collect_in<A: Allocator>(self, alloc: A) -> Result<Vec<T, A>, TryReserveError>;
fn try_collect(self) -> Result<Vec<T>, TryReserveError>;
}
impl<T, I> TryCollect<T> for I
where
I: IntoIterator<Item = T>,
{
#[cfg(feature = "allocator_api")]
fn try_collect_in<A: Allocator>(self, alloc: A) -> Result<Vec<T, A>, TryReserveError> {
let mut vec = Vec::new_in(alloc);
vec.try_extend(self.into_iter())?;
Ok(vec)
}
fn try_collect(self) -> Result<Vec<T>, TryReserveError> {
let mut vec = Vec::new();
vec.try_extend(self.into_iter())?;
Ok(vec)
}
}