2424mod all;
2525mod any;
2626mod filter_map;
27+ mod find;
2728mod find_map;
2829mod min_by;
2930mod next;
@@ -35,6 +36,7 @@ pub use take::Take;
3536use all:: AllFuture ;
3637use any:: AnyFuture ;
3738use filter_map:: FilterMap ;
39+ use find:: FindFuture ;
3840use find_map:: FindMapFuture ;
3941use min_by:: MinByFuture ;
4042use next:: NextFuture ;
@@ -321,6 +323,50 @@ pub trait Stream {
321323 }
322324 }
323325
326+ /// Searches for an element in a stream that satisfies a predicate.
327+ ///
328+ /// # Examples
329+ ///
330+ /// Basic usage:
331+ ///
332+ /// ```
333+ /// # fn main() { async_std::task::block_on(async {
334+ /// #
335+ /// use async_std::prelude::*;
336+ /// use std::collections::VecDeque;
337+ ///
338+ /// let mut s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
339+ /// let res = s.find(|x| *x == 2).await;
340+ /// assert_eq!(res, Some(2));
341+ /// #
342+ /// # }) }
343+ /// ```
344+ ///
345+ /// Resuming after a first find:
346+ ///
347+ /// ```
348+ /// # fn main() { async_std::task::block_on(async {
349+ /// #
350+ /// use async_std::prelude::*;
351+ /// use std::collections::VecDeque;
352+ ///
353+ /// let mut s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
354+ /// let res = s.find(|x| *x == 2).await;
355+ /// assert_eq!(res, Some(2));
356+ ///
357+ /// let next = s.next().await;
358+ /// assert_eq!(next, Some(3));
359+ /// #
360+ /// # }) }
361+ /// ```
362+ fn find < P > ( & mut self , p : P ) -> ret ! ( ' _, FindFuture , Option <Self :: Item >, P , Self :: Item )
363+ where
364+ Self : Sized ,
365+ P : FnMut ( & Self :: Item ) -> bool ,
366+ {
367+ FindFuture :: new ( self , p)
368+ }
369+
324370 /// Applies function to the elements of stream and returns the first non-none result.
325371 ///
326372 /// ```
0 commit comments