use core::{fmt, marker};
use crate::{
DoubleEndedFallibleLender, ExactSizeFallibleLender, FallibleLend, FallibleLender,
FallibleLending, FusedFallibleLender,
};
#[inline(always)]
pub const fn empty<L: ?Sized + for<'all> FallibleLending<'all>, E>() -> Empty<L, E> {
Empty(marker::PhantomData)
}
#[must_use = "lenders are lazy and do nothing unless consumed"]
#[derive(Clone, Copy, Default)]
#[allow(clippy::type_complexity)]
pub struct Empty<L: ?Sized, E>(marker::PhantomData<(fn() -> E, fn() -> L)>);
impl<L: ?Sized, E> fmt::Debug for Empty<L, E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FallibleEmpty").finish()
}
}
impl<'lend, L, E> FallibleLending<'lend> for Empty<L, E>
where
L: ?Sized + for<'all> FallibleLending<'all>,
{
type Lend = FallibleLend<'lend, L>;
}
impl<L, E> FallibleLender for Empty<L, E>
where
L: ?Sized + for<'all> FallibleLending<'all>,
{
type Error = E;
crate::unsafe_assume_covariance_fallible!();
#[inline(always)]
fn next(&mut self) -> Result<Option<FallibleLend<'_, Self>>, Self::Error> {
Ok(None)
}
#[inline(always)]
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}
impl<L, E> DoubleEndedFallibleLender for Empty<L, E>
where
L: ?Sized + for<'all> FallibleLending<'all>,
{
#[inline(always)]
fn next_back(&mut self) -> Result<Option<FallibleLend<'_, Self>>, Self::Error> {
Ok(None)
}
}
impl<L, E> ExactSizeFallibleLender for Empty<L, E> where L: ?Sized + for<'all> FallibleLending<'all> {}
impl<L, E> FusedFallibleLender for Empty<L, E> where L: ?Sized + for<'all> FallibleLending<'all> {}