use core::convert::Infallible;
use core::fmt::Debug;
use crate::prelude::*;
#[derive(Debug, Clone, Copy)]
pub struct Full<T>(Option<T>);
pub fn full<T>() -> Full<T> {
Full(None)
}
impl<T> Full<T> {
pub fn into_final(self) -> Option<T> {
self.0
}
}
impl<T> Consumer for Full<T> {
type Item = Infallible;
type Final = T;
type Error = Infallible;
async fn consume(&mut self, val: Either<Self::Item, Self::Final>) -> Result<(), Self::Error> {
match val {
Left(_) => unreachable!(),
Right(fin) => {
self.0 = Some(fin);
Ok(())
}
}
}
async fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}