forked from mirror/async-std
feat: Add FlattenCompat struct
This commit is contained in:
parent
46f0fb1c64
commit
ec98b41c85
3 changed files with 26 additions and 0 deletions
|
@ -47,6 +47,7 @@
|
|||
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
|
||||
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
|
||||
#![recursion_limit = "1024"]
|
||||
#![feature(associated_type_bounds)]
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
|
|
24
src/stream/stream/flatten.rs
Normal file
24
src/stream/stream/flatten.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use std::pin::Pin;
|
||||
|
||||
use crate::stream::{IntoStream, Stream};
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
/// Real logic of both `Flatten` and `FlatMap` which simply delegate to
|
||||
/// this type.
|
||||
#[derive(Clone, Debug)]
|
||||
struct FlattenCompat<S, U> {
|
||||
stream: S,
|
||||
frontiter: Option<U>,
|
||||
}
|
||||
impl<S, U> FlattenCompat<S, U> {
|
||||
pin_utils::unsafe_unpinned!(stream: S);
|
||||
pin_utils::unsafe_unpinned!(frontiter: Option<U>);
|
||||
|
||||
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
|
||||
pub fn new(stream: S) -> FlattenCompat<S, U> {
|
||||
FlattenCompat {
|
||||
stream,
|
||||
frontiter: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -106,6 +106,7 @@ cfg_if! {
|
|||
cfg_if! {
|
||||
if #[cfg(any(feature = "unstable", feature = "docs"))] {
|
||||
mod merge;
|
||||
mod flatten;
|
||||
|
||||
use std::pin::Pin;
|
||||
|
||||
|
|
Loading…
Reference in a new issue