Make the closure take a borrow to the value

new-scheduler
Felipe Sere 5 years ago
parent bfb42b432e
commit 7677e9a3df

@ -18,7 +18,7 @@ use pin_project_lite::pin_project;
/// use async_std::prelude::*; /// use async_std::prelude::*;
/// use async_std::stream; /// use async_std::stream;
/// ///
/// let s = stream::successors(Some(22), |val| { /// let s = stream::successors(Some(22), |&val| {
/// async move { /// async move {
/// Some(val + 1) /// Some(val + 1)
/// } /// }
@ -31,9 +31,9 @@ use pin_project_lite::pin_project;
/// assert_eq!(s.next().await, Some(25)); /// assert_eq!(s.next().await, Some(25));
/// ///
/// ///
///let never = stream::successors(None, |val: usize| { ///let never = stream::successors(None, |_| {
/// async move { /// async move {
/// Some(val + 1) /// Some(1)
/// } /// }
/// }); /// });
/// ///
@ -48,7 +48,7 @@ use pin_project_lite::pin_project;
#[cfg_attr(feature = "docs", doc(cfg(unstable)))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))]
pub fn successors<F, Fut, T>(first: Option<T>, succ: F) -> Successors<F, Fut, T> pub fn successors<F, Fut, T>(first: Option<T>, succ: F) -> Successors<F, Fut, T>
where where
F: FnMut(T) -> Fut, F: FnMut(&T) -> Fut,
Fut: Future<Output = Option<T>>, Fut: Future<Output = Option<T>>,
T: Copy, T: Copy,
{ {
@ -83,7 +83,7 @@ pin_project! {
impl<F, Fut, T> Stream for Successors<F, Fut, T> impl<F, Fut, T> Stream for Successors<F, Fut, T>
where where
Fut: Future<Output = Option<T>>, Fut: Future<Output = Option<T>>,
F: FnMut(T) -> Fut, F: FnMut(&T) -> Fut,
T: Copy, T: Copy,
{ {
type Item = T; type Item = T;
@ -96,7 +96,7 @@ where
} }
if this.future.is_none() { if this.future.is_none() {
let fut = (this.succ)(this.slot.unwrap()); let fut = (this.succ)(&this.slot.unwrap());
this.future.set(Some(fut)); this.future.set(Some(fut));
} }

Loading…
Cancel
Save