From 7677e9a3dfdada2bf8f97eadb286258c194c1e4b Mon Sep 17 00:00:00 2001 From: Felipe Sere Date: Mon, 11 Nov 2019 09:13:57 +0100 Subject: [PATCH] Make the closure take a borrow to the value --- src/stream/successors.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/stream/successors.rs b/src/stream/successors.rs index f7d5bd8..446ffe5 100644 --- a/src/stream/successors.rs +++ b/src/stream/successors.rs @@ -18,7 +18,7 @@ use pin_project_lite::pin_project; /// use async_std::prelude::*; /// use async_std::stream; /// -/// let s = stream::successors(Some(22), |val| { +/// let s = stream::successors(Some(22), |&val| { /// async move { /// Some(val + 1) /// } @@ -31,9 +31,9 @@ use pin_project_lite::pin_project; /// assert_eq!(s.next().await, Some(25)); /// /// -///let never = stream::successors(None, |val: usize| { +///let never = stream::successors(None, |_| { /// async move { -/// Some(val + 1) +/// Some(1) /// } /// }); /// @@ -48,7 +48,7 @@ use pin_project_lite::pin_project; #[cfg_attr(feature = "docs", doc(cfg(unstable)))] pub fn successors(first: Option, succ: F) -> Successors where - F: FnMut(T) -> Fut, + F: FnMut(&T) -> Fut, Fut: Future>, T: Copy, { @@ -83,7 +83,7 @@ pin_project! { impl Stream for Successors where Fut: Future>, - F: FnMut(T) -> Fut, + F: FnMut(&T) -> Fut, T: Copy, { type Item = T; @@ -96,7 +96,7 @@ where } if this.future.is_none() { - let fut = (this.succ)(this.slot.unwrap()); + let fut = (this.succ)(&this.slot.unwrap()); this.future.set(Some(fut)); }