Skip to content

Commit ec98b41

Browse files
committed
feat: Add FlattenCompat struct
1 parent 46f0fb1 commit ec98b41

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
4848
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
4949
#![recursion_limit = "1024"]
50+
#![feature(associated_type_bounds)]
5051

5152
use cfg_if::cfg_if;
5253

src/stream/stream/flatten.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::pin::Pin;
2+
3+
use crate::stream::{IntoStream, Stream};
4+
use crate::task::{Context, Poll};
5+
6+
/// Real logic of both `Flatten` and `FlatMap` which simply delegate to
7+
/// this type.
8+
#[derive(Clone, Debug)]
9+
struct FlattenCompat<S, U> {
10+
stream: S,
11+
frontiter: Option<U>,
12+
}
13+
impl<S, U> FlattenCompat<S, U> {
14+
pin_utils::unsafe_unpinned!(stream: S);
15+
pin_utils::unsafe_unpinned!(frontiter: Option<U>);
16+
17+
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
18+
pub fn new(stream: S) -> FlattenCompat<S, U> {
19+
FlattenCompat {
20+
stream,
21+
frontiter: None,
22+
}
23+
}
24+
}

src/stream/stream/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ cfg_if! {
106106
cfg_if! {
107107
if #[cfg(any(feature = "unstable", feature = "docs"))] {
108108
mod merge;
109+
mod flatten;
109110

110111
use std::pin::Pin;
111112

0 commit comments

Comments
 (0)