Skip to content

Commit 96c7f97

Browse files
authored
Merge pull request #1118 from TannerRogalsky/native-web-fixes
Native web fixes.
2 parents aeec037 + 24d7d47 commit 96c7f97

File tree

3 files changed

+53
-29
lines changed

3 files changed

+53
-29
lines changed

futures/src/lib.rs

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,58 @@ pub mod time;
3737

3838
pub use command::Command;
3939
pub use executor::Executor;
40+
pub use platform::*;
4041
pub use runtime::Runtime;
4142
pub use subscription::Subscription;
4243

43-
/// A boxed static future.
44-
///
45-
/// - On native platforms, it needs a `Send` requirement.
46-
/// - On the Web platform, it does not need a `Send` requirement.
4744
#[cfg(not(target_arch = "wasm32"))]
48-
pub type BoxFuture<T> = futures::future::BoxFuture<'static, T>;
45+
mod platform {
46+
/// A boxed static future.
47+
///
48+
/// - On native platforms, it needs a `Send` requirement.
49+
/// - On the Web platform, it does not need a `Send` requirement.
50+
pub type BoxFuture<T> = futures::future::BoxFuture<'static, T>;
4951

50-
/// A boxed static future.
51-
///
52-
/// - On native platforms, it needs a `Send` requirement.
53-
/// - On the Web platform, it does not need a `Send` requirement.
54-
#[cfg(target_arch = "wasm32")]
55-
pub type BoxFuture<T> = futures::future::LocalBoxFuture<'static, T>;
52+
/// A boxed static stream.
53+
///
54+
/// - On native platforms, it needs a `Send` requirement.
55+
/// - On the Web platform, it does not need a `Send` requirement.
56+
pub type BoxStream<T> = futures::stream::BoxStream<'static, T>;
5657

57-
/// A boxed static stream.
58-
///
59-
/// - On native platforms, it needs a `Send` requirement.
60-
/// - On the Web platform, it does not need a `Send` requirement.
61-
#[cfg(not(target_arch = "wasm32"))]
62-
pub type BoxStream<T> = futures::stream::BoxStream<'static, T>;
58+
/// Boxes a stream.
59+
///
60+
/// - On native platforms, it needs a `Send` requirement.
61+
/// - On the Web platform, it does not need a `Send` requirement.
62+
pub fn boxed_stream<T, S>(stream: S) -> BoxStream<T>
63+
where
64+
S: futures::Stream<Item = T> + Send + 'static,
65+
{
66+
futures::stream::StreamExt::boxed(stream)
67+
}
68+
}
6369

64-
/// A boxed static stream.
65-
///
66-
/// - On native platforms, it needs a `Send` requirement.
67-
/// - On the Web platform, it does not need a `Send` requirement.
6870
#[cfg(target_arch = "wasm32")]
69-
pub type BoxStream<T> = futures::stream::LocalBoxStream<'static, T>;
71+
mod platform {
72+
/// A boxed static future.
73+
///
74+
/// - On native platforms, it needs a `Send` requirement.
75+
/// - On the Web platform, it does not need a `Send` requirement.
76+
pub type BoxFuture<T> = futures::future::LocalBoxFuture<'static, T>;
77+
78+
/// A boxed static stream.
79+
///
80+
/// - On native platforms, it needs a `Send` requirement.
81+
/// - On the Web platform, it does not need a `Send` requirement.
82+
pub type BoxStream<T> = futures::stream::LocalBoxStream<'static, T>;
83+
84+
/// Boxes a stream.
85+
///
86+
/// - On native platforms, it needs a `Send` requirement.
87+
/// - On the Web platform, it does not need a `Send` requirement.
88+
pub fn boxed_stream<T, S>(stream: S) -> BoxStream<T>
89+
where
90+
S: futures::Stream<Item = T> + 'static,
91+
{
92+
futures::stream::StreamExt::boxed_local(stream)
93+
}
94+
}

native/src/subscription.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Listen to external events in your application.
22
use crate::event::{self, Event};
33
use crate::Hasher;
4-
use iced_futures::futures::stream::BoxStream;
4+
use iced_futures::BoxStream;
55

66
/// A request to listen to external events.
77
///
@@ -21,7 +21,7 @@ pub type Subscription<T> =
2121
/// A stream of runtime events.
2222
///
2323
/// It is the input of a [`Subscription`] in the native runtime.
24-
pub type EventStream = BoxStream<'static, (Event, event::Status)>;
24+
pub type EventStream = BoxStream<(Event, event::Status)>;
2525

2626
/// A native [`Subscription`] tracker.
2727
pub type Tracker =

native/src/subscription/events.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ where
2727
self: Box<Self>,
2828
event_stream: EventStream,
2929
) -> BoxStream<Self::Output> {
30-
event_stream
31-
.filter_map(move |(event, status)| {
32-
future::ready((self.f)(event, status))
33-
})
34-
.boxed()
30+
let stream = event_stream.filter_map(move |(event, status)| {
31+
future::ready((self.f)(event, status))
32+
});
33+
iced_futures::boxed_stream(stream)
3534
}
3635
}

0 commit comments

Comments
 (0)