iced_futures/lib.rs
1//! Asynchronous tasks for GUI programming, inspired by Elm.
2//!
3//! 
4#![doc(
5 html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
6)]
7#![cfg_attr(docsrs, feature(doc_auto_cfg))]
8pub use futures;
9pub use iced_core as core;
10
11mod maybe;
12mod runtime;
13
14pub mod backend;
15pub mod event;
16pub mod executor;
17pub mod keyboard;
18pub mod stream;
19pub mod subscription;
20
21pub use executor::Executor;
22pub use maybe::{MaybeSend, MaybeSync};
23pub use platform::*;
24pub use runtime::Runtime;
25pub use subscription::Subscription;
26
27#[cfg(not(target_arch = "wasm32"))]
28mod platform {
29 /// A boxed static future.
30 ///
31 /// - On native platforms, it needs a `Send` requirement.
32 /// - On the Web platform, it does not need a `Send` requirement.
33 pub type BoxFuture<T> = futures::future::BoxFuture<'static, T>;
34
35 /// A boxed static stream.
36 ///
37 /// - On native platforms, it needs a `Send` requirement.
38 /// - On the Web platform, it does not need a `Send` requirement.
39 pub type BoxStream<T> = futures::stream::BoxStream<'static, T>;
40
41 /// Boxes a stream.
42 ///
43 /// - On native platforms, it needs a `Send` requirement.
44 /// - On the Web platform, it does not need a `Send` requirement.
45 pub fn boxed_stream<T, S>(stream: S) -> BoxStream<T>
46 where
47 S: futures::Stream<Item = T> + Send + 'static,
48 {
49 futures::stream::StreamExt::boxed(stream)
50 }
51}
52
53#[cfg(target_arch = "wasm32")]
54mod platform {
55 /// A boxed static future.
56 ///
57 /// - On native platforms, it needs a `Send` requirement.
58 /// - On the Web platform, it does not need a `Send` requirement.
59 pub type BoxFuture<T> = futures::future::LocalBoxFuture<'static, T>;
60
61 /// A boxed static stream.
62 ///
63 /// - On native platforms, it needs a `Send` requirement.
64 /// - On the Web platform, it does not need a `Send` requirement.
65 pub type BoxStream<T> = futures::stream::LocalBoxStream<'static, T>;
66
67 /// Boxes a stream.
68 ///
69 /// - On native platforms, it needs a `Send` requirement.
70 /// - On the Web platform, it does not need a `Send` requirement.
71 pub fn boxed_stream<T, S>(stream: S) -> BoxStream<T>
72 where
73 S: futures::Stream<Item = T> + 'static,
74 {
75 futures::stream::StreamExt::boxed_local(stream)
76 }
77}