Skip to content

Commit 18428d6

Browse files
committed
housekeeping after 145
1 parent 2ecaf18 commit 18428d6

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

src/stream/stream/filter_map.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use std::marker::PhantomData;
22
use std::pin::Pin;
33
use std::task::{Context, Poll};
44

5-
/// A stream that both filters and maps.
6-
#[derive(Clone, Debug)]
5+
use crate::stream::Stream;
6+
7+
#[doc(hidden)]
8+
#[allow(missing_debug_implementations)]
79
pub struct FilterMap<S, F, T, B> {
810
stream: S,
911
f: F,
@@ -27,7 +29,7 @@ impl<S, F, T, B> FilterMap<S, F, T, B> {
2729

2830
impl<S, F, B> futures_core::stream::Stream for FilterMap<S, F, S::Item, B>
2931
where
30-
S: futures_core::stream::Stream,
32+
S: Stream,
3133
F: FnMut(S::Item) -> Option<B>,
3234
{
3335
type Item = B;

src/stream/stream/find.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
use crate::task::{Context, Poll};
21
use std::marker::PhantomData;
32
use std::pin::Pin;
43

4+
use crate::future::Future;
5+
use crate::stream::Stream;
6+
use crate::task::{Context, Poll};
7+
58
#[doc(hidden)]
69
#[allow(missing_debug_implementations)]
710
pub struct FindFuture<'a, S, P, T> {
@@ -11,9 +14,6 @@ pub struct FindFuture<'a, S, P, T> {
1114
}
1215

1316
impl<'a, S, P, T> FindFuture<'a, S, P, T> {
14-
pin_utils::unsafe_pinned!(stream: &'a mut S);
15-
pin_utils::unsafe_unpinned!(p: P);
16-
1717
pub(super) fn new(stream: &'a mut S, p: P) -> Self {
1818
FindFuture {
1919
stream,
@@ -23,20 +23,20 @@ impl<'a, S, P, T> FindFuture<'a, S, P, T> {
2323
}
2424
}
2525

26-
impl<'a, S, P> futures_core::future::Future for FindFuture<'a, S, P, S::Item>
26+
impl<S: Unpin, P, T> Unpin for FindFuture<'_, S, P, T> {}
27+
28+
impl<'a, S, P> Future for FindFuture<'a, S, P, S::Item>
2729
where
28-
S: futures_core::stream::Stream + Unpin + Sized,
30+
S: Stream + Unpin + Sized,
2931
P: FnMut(&S::Item) -> bool,
3032
{
3133
type Output = Option<S::Item>;
3234

3335
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
34-
use futures_core::stream::Stream;
35-
36-
let item = futures_core::ready!(self.as_mut().stream().poll_next(cx));
36+
let item = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx));
3737

3838
match item {
39-
Some(v) => match (self.as_mut().p())(&v) {
39+
Some(v) => match (&mut self.p)(&v) {
4040
true => Poll::Ready(Some(v)),
4141
false => {
4242
cx.waker().wake_by_ref();

src/stream/stream/find_map.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ use std::marker::PhantomData;
22
use std::pin::Pin;
33
use std::task::{Context, Poll};
44

5+
use crate::future::Future;
6+
use crate::stream::Stream;
7+
8+
#[doc(hidden)]
59
#[allow(missing_debug_implementations)]
610
pub struct FindMapFuture<'a, S, F, T, B> {
711
stream: &'a mut S,
@@ -11,9 +15,6 @@ pub struct FindMapFuture<'a, S, F, T, B> {
1115
}
1216

1317
impl<'a, S, B, F, T> FindMapFuture<'a, S, F, T, B> {
14-
pin_utils::unsafe_pinned!(stream: &'a mut S);
15-
pin_utils::unsafe_unpinned!(f: F);
16-
1718
pub(super) fn new(stream: &'a mut S, f: F) -> Self {
1819
FindMapFuture {
1920
stream,
@@ -24,20 +25,20 @@ impl<'a, S, B, F, T> FindMapFuture<'a, S, F, T, B> {
2425
}
2526
}
2627

27-
impl<'a, S, B, F> futures_core::future::Future for FindMapFuture<'a, S, F, S::Item, B>
28+
impl<S: Unpin, F, T, B> Unpin for FindMapFuture<'_, S, F, T, B> {}
29+
30+
impl<'a, S, B, F> Future for FindMapFuture<'a, S, F, S::Item, B>
2831
where
29-
S: futures_core::stream::Stream + Unpin + Sized,
32+
S: Stream + Unpin + Sized,
3033
F: FnMut(S::Item) -> Option<B>,
3134
{
3235
type Output = Option<B>;
3336

3437
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
35-
use futures_core::stream::Stream;
36-
37-
let item = futures_core::ready!(self.as_mut().stream().poll_next(cx));
38+
let item = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx));
3839

3940
match item {
40-
Some(v) => match (self.as_mut().f())(v) {
41+
Some(v) => match (&mut self.f)(v) {
4142
Some(v) => Poll::Ready(Some(v)),
4243
None => {
4344
cx.waker().wake_by_ref();

src/stream/stream/nth.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
use std::pin::Pin;
22
use std::task::{Context, Poll};
33

4+
use crate::future::Future;
5+
use crate::stream::Stream;
6+
7+
#[doc(hidden)]
48
#[allow(missing_debug_implementations)]
59
pub struct NthFuture<'a, S> {
610
stream: &'a mut S,
711
n: usize,
812
}
913

10-
impl<'a, S> NthFuture<'a, S> {
11-
pin_utils::unsafe_pinned!(stream: &'a mut S);
12-
pin_utils::unsafe_unpinned!(n: usize);
14+
impl<S: Unpin> Unpin for NthFuture<'_, S> {}
1315

16+
impl<'a, S> NthFuture<'a, S> {
1417
pub(crate) fn new(stream: &'a mut S, n: usize) -> Self {
1518
NthFuture { stream, n }
1619
}
1720
}
1821

19-
impl<'a, S> futures_core::future::Future for NthFuture<'a, S>
22+
impl<'a, S> Future for NthFuture<'a, S>
2023
where
21-
S: futures_core::stream::Stream + Unpin + Sized,
24+
S: Stream + Unpin + Sized,
2225
{
2326
type Output = Option<S::Item>;
2427

2528
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
26-
use futures_core::stream::Stream;
27-
28-
let next = futures_core::ready!(self.as_mut().stream().poll_next(cx));
29+
let next = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx));
2930
match next {
3031
Some(v) => match self.n {
3132
0 => Poll::Ready(Some(v)),
3233
_ => {
33-
*self.as_mut().n() -= 1;
34+
self.n -= 1;
3435
cx.waker().wake_by_ref();
3536
Poll::Pending
3637
}

0 commit comments

Comments
 (0)