use core::{fmt, marker};
use crate::{DoubleEndedLender, ExactSizeLender, FusedLender, Lend, Lender, Lending};
#[inline(always)]
pub const fn empty<L: ?Sized + for<'all> Lending<'all>>() -> Empty<L> {
Empty(marker::PhantomData)
}
#[must_use = "lenders are lazy and do nothing unless consumed"]
#[derive(Clone, Copy, Default)]
pub struct Empty<L: ?Sized>(marker::PhantomData<fn() -> L>);
impl<L: ?Sized> fmt::Debug for Empty<L> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Empty").finish()
}
}
impl<'lend, L> Lending<'lend> for Empty<L>
where
L: ?Sized + for<'all> Lending<'all>,
{
type Lend = Lend<'lend, L>;
}
impl<L> Lender for Empty<L>
where
L: ?Sized + for<'all> Lending<'all>,
{
crate::unsafe_assume_covariance!();
#[inline(always)]
fn next(&mut self) -> Option<Lend<'_, Self>> {
None
}
#[inline(always)]
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}
impl<L> DoubleEndedLender for Empty<L>
where
L: ?Sized + for<'all> Lending<'all>,
{
#[inline(always)]
fn next_back(&mut self) -> Option<Lend<'_, Self>> {
None
}
}
impl<L> ExactSizeLender for Empty<L> where L: ?Sized + for<'all> Lending<'all> {}
impl<L> FusedLender for Empty<L> where L: ?Sized + for<'all> Lending<'all> {}