use std::collections::VecDeque;
use crate::{
prelude::*,
producer::compat::{iterator_to_producer, IteratorToProducer},
};
pub struct IntoProducer<T>(IteratorToProducer<<VecDeque<T> as IntoIterator>::IntoIter>);
impl<T> Producer for IntoProducer<T> {
type Item = T;
type Final = ();
type Error = Infallible;
async fn produce(&mut self) -> Result<Either<Self::Item, Self::Final>, Self::Error> {
self.0.produce().await
}
async fn slurp(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
impl<T> crate::IntoProducer for VecDeque<T> {
type Item = T;
type Final = ();
type Error = Infallible;
type IntoProducer = IntoProducer<T>;
fn into_producer(self) -> Self::IntoProducer {
IntoProducer(iterator_to_producer(
<VecDeque<T> as IntoIterator>::into_iter(self),
))
}
}
pub struct IntoProducerRef<'s, T>(IteratorToProducer<<&'s VecDeque<T> as IntoIterator>::IntoIter>);
impl<'s, T> Producer for IntoProducerRef<'s, T> {
type Item = &'s T;
type Final = ();
type Error = Infallible;
async fn produce(&mut self) -> Result<Either<Self::Item, Self::Final>, Self::Error> {
self.0.produce().await
}
async fn slurp(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
impl<'s, T> crate::IntoProducer for &'s VecDeque<T> {
type Item = &'s T;
type Final = ();
type Error = Infallible;
type IntoProducer = IntoProducerRef<'s, T>;
fn into_producer(self) -> Self::IntoProducer {
IntoProducerRef(iterator_to_producer(self.iter()))
}
}
pub struct IntoProducerMut<'s, T>(
IteratorToProducer<<&'s mut VecDeque<T> as IntoIterator>::IntoIter>,
);
impl<'s, T> Producer for IntoProducerMut<'s, T> {
type Item = &'s mut T;
type Final = ();
type Error = Infallible;
async fn produce(&mut self) -> Result<Either<Self::Item, Self::Final>, Self::Error> {
self.0.produce().await
}
async fn slurp(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
impl<'s, T> crate::IntoProducer for &'s mut VecDeque<T> {
type Item = &'s mut T;
type Final = ();
type Error = Infallible;
type IntoProducer = IntoProducerMut<'s, T>;
fn into_producer(self) -> Self::IntoProducer {
IntoProducerMut(iterator_to_producer(self.iter_mut()))
}
}