From bdca20fc4a3e8f6bd8ffb59de75e6ca0f8a94b6a Mon Sep 17 00:00:00 2001 From: Vladyslav Nikonov Date: Thu, 21 Oct 2021 22:42:14 +0300 Subject: Experimental wgpu WebGL backend support - Added missing `draw_cache_align_4x4` call for `brush_glyph` on wasm32 target - Added WebGL support to `integratio_wgpu` example - Fixed test.yml CI workflow - Removed spir-v shader in `integration_wgpu`; Fixed formatting - Removed redundant `BoxStream` typedef --- native/src/subscription.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'native/src/subscription.rs') diff --git a/native/src/subscription.rs b/native/src/subscription.rs index 63834654..4fb7e760 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -7,6 +7,37 @@ use iced_futures::BoxStream; use std::hash::Hash; +#[cfg(not(target_arch = "wasm32"))] +mod trait_aliases { + use super::*; + + /// Wrapper type + pub trait RunnerStream: + Stream + Send + 'static + { + } + + impl RunnerStream for T where + T: Stream + Send + 'static + { + } +} + +#[cfg(target_arch = "wasm32")] +mod trait_aliases { + use super::*; + + /// Wrapper type + pub trait RunnerStream: Stream + 'static {} + + impl RunnerStream for T where + T: Stream + 'static + { + } +} + +pub use trait_aliases::RunnerStream; + /// A request to listen to external events. /// /// Besides performing async actions on demand with [`Command`], most @@ -191,7 +222,7 @@ impl Recipe where I: Hash + 'static, F: FnOnce(EventStream) -> S, - S: Stream + Send + 'static, + S: RunnerStream, { type Output = Message; @@ -203,6 +234,13 @@ where fn stream(self: Box, input: EventStream) -> BoxStream { use futures::stream::StreamExt; - (self.spawn)(input).boxed() + #[cfg(target_arch = "wasm32")] + { + (self.spawn)(input).boxed_local() + } + #[cfg(not(target_arch = "wasm32"))] + { + (self.spawn)(input).boxed() + } } } -- cgit From 5dab5a327ef643ee38ac3e42ab35212fff445631 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 28 Jan 2022 17:35:47 +0700 Subject: Introduce `MaybeSend` trait in `iced_futures` It allows to clean up all the `trait_aliases` modules! --- native/src/subscription.rs | 58 +++++++--------------------------------------- 1 file changed, 9 insertions(+), 49 deletions(-) (limited to 'native/src/subscription.rs') diff --git a/native/src/subscription.rs b/native/src/subscription.rs index 4fb7e760..9775c84b 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -3,41 +3,10 @@ use crate::event::{self, Event}; use crate::Hasher; use iced_futures::futures::{self, Future, Stream}; -use iced_futures::BoxStream; +use iced_futures::{BoxStream, MaybeSend}; use std::hash::Hash; -#[cfg(not(target_arch = "wasm32"))] -mod trait_aliases { - use super::*; - - /// Wrapper type - pub trait RunnerStream: - Stream + Send + 'static - { - } - - impl RunnerStream for T where - T: Stream + Send + 'static - { - } -} - -#[cfg(target_arch = "wasm32")] -mod trait_aliases { - use super::*; - - /// Wrapper type - pub trait RunnerStream: Stream + 'static {} - - impl RunnerStream for T where - T: Stream + 'static - { - } -} - -pub use trait_aliases::RunnerStream; - /// A request to listen to external events. /// /// Besides performing async actions on demand with [`Command`], most @@ -87,7 +56,7 @@ pub fn events_with( f: fn(Event, event::Status) -> Option, ) -> Subscription where - Message: 'static + Send, + Message: 'static + MaybeSend, { Subscription::from_recipe(Runner { id: f, @@ -109,7 +78,7 @@ where pub fn run(id: I, stream: S) -> Subscription where I: Hash + 'static, - S: Stream + Send + 'static, + S: Stream + MaybeSend + 'static, Message: 'static, { Subscription::from_recipe(Runner { @@ -190,13 +159,13 @@ where pub fn unfold( id: I, initial: T, - mut f: impl FnMut(T) -> Fut + Send + Sync + 'static, + mut f: impl FnMut(T) -> Fut + MaybeSend + Sync + 'static, ) -> Subscription where I: Hash + 'static, - T: Send + 'static, - Fut: Future, T)> + Send + 'static, - Message: 'static + Send, + T: MaybeSend + 'static, + Fut: Future, T)> + MaybeSend + 'static, + Message: 'static + MaybeSend, { use futures::future::{self, FutureExt}; use futures::stream::StreamExt; @@ -222,7 +191,7 @@ impl Recipe where I: Hash + 'static, F: FnOnce(EventStream) -> S, - S: RunnerStream, + S: Stream + MaybeSend + 'static, { type Output = Message; @@ -232,15 +201,6 @@ where } fn stream(self: Box, input: EventStream) -> BoxStream { - use futures::stream::StreamExt; - - #[cfg(target_arch = "wasm32")] - { - (self.spawn)(input).boxed_local() - } - #[cfg(not(target_arch = "wasm32"))] - { - (self.spawn)(input).boxed() - } + iced_futures::boxed_stream((self.spawn)(input)) } } -- cgit