use std::{
pin::Pin,
sync::Arc,
task::{Context, Poll},
};
use futures::Stream;
use crate::{
pollable::PollProxy,
selector::{Id, Selector},
};
pub struct WithExt<'s, 'e, 'emut, T, P, E: ?Sized, EMut: ?Sized> {
pub(super) selector: &'s mut Selector<T, P>,
pub(super) ext: &'e E,
pub(super) ext_mut: &'emut mut EMut,
}
impl<'e, T, P, E, EMut> Stream for WithExt<'_, 'e, '_, T, P, E, EMut>
where
P: PollProxy<'e, T, E, EMut>,
E: ?Sized,
EMut: ?Sized,
{
type Item = P::Progress;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
this.selector
.poll_next_inner(this.ext, this.ext_mut, |_| (), cx)
.map(|opt| opt.map(|(result, ())| result))
}
}
pub struct WithId<'s, T, P> {
pub(super) selector: &'s mut Selector<T, P>,
}
impl<T, P> Stream for WithId<'_, T, P>
where
P: PollProxy<'static, T, (), ()>,
{
type Item = (P::Progress, Id<T>);
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.get_mut()
.selector
.poll_next_inner(&(), &mut (), |task| Id(Arc::downgrade(task)), cx)
}
}
pub struct WithExtAndId<'s, 'e, 'emut, T, P, E: ?Sized, EMut: ?Sized> {
pub(super) selector: &'s mut Selector<T, P>,
pub(super) ext: &'e E,
pub(super) ext_mut: &'emut mut EMut,
}
impl<'e, T, P, E, EMut> Stream for WithExtAndId<'_, 'e, '_, T, P, E, EMut>
where
P: PollProxy<'e, T, E, EMut>,
E: ?Sized,
EMut: ?Sized,
{
type Item = (P::Progress, Id<T>);
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
this.selector
.poll_next_inner(this.ext, this.ext_mut, |task| Id(Arc::downgrade(task)), cx)
}
}