From 9ca65c9f18454ba2bb3ff5667d9618a1491771db Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 18 Dec 2019 23:57:02 +0100 Subject: Fix missing `Subscription` type in `iced_web` --- src/application.rs | 4 ++-- web/Cargo.toml | 2 +- web/src/hasher.rs | 21 +++++++++++++++++++++ web/src/lib.rs | 4 ++++ web/src/subscription.rs | 19 +++++++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 web/src/hasher.rs create mode 100644 web/src/subscription.rs diff --git a/src/application.rs b/src/application.rs index 98e160ce..a7e826fb 100644 --- a/src/application.rs +++ b/src/application.rs @@ -146,12 +146,12 @@ pub trait Application: Sized { /// It should probably be that last thing you call in your `main` function. /// /// [`Application`]: trait.Application.html - fn run(settings: Settings) + fn run(_settings: Settings) where Self: 'static, { #[cfg(not(target_arch = "wasm32"))] - as iced_winit::Application>::run(settings.into()); + as iced_winit::Application>::run(_settings.into()); #[cfg(target_arch = "wasm32")] as iced_web::Application>::run(); diff --git a/web/Cargo.toml b/web/Cargo.toml index 8c559d73..605c7462 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -15,7 +15,7 @@ categories = ["web-programming"] maintenance = { status = "actively-developed" } [dependencies] -iced_core = { version = "0.1.0", path = "../core", features = ["command"] } +iced_core = { version = "0.1.0", path = "../core", features = ["command", "subscription"] } dodrio = "0.1.0" wasm-bindgen = "0.2.51" wasm-bindgen-futures = "0.4" diff --git a/web/src/hasher.rs b/web/src/hasher.rs new file mode 100644 index 00000000..9ce2f7be --- /dev/null +++ b/web/src/hasher.rs @@ -0,0 +1,21 @@ +use std::collections::hash_map::DefaultHasher; + +/// The hasher used to compare layouts. +#[derive(Debug)] +pub struct Hasher(DefaultHasher); + +impl Default for Hasher { + fn default() -> Self { + Hasher(DefaultHasher::default()) + } +} + +impl core::hash::Hasher for Hasher { + fn write(&mut self, bytes: &[u8]) { + self.0.write(bytes) + } + + fn finish(&self) -> u64 { + self.0.finish() + } +} diff --git a/web/src/lib.rs b/web/src/lib.rs index 782bcf93..d4c422d2 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -61,18 +61,22 @@ use std::{cell::RefCell, rc::Rc}; mod bus; mod element; +mod hasher; pub mod style; +pub mod subscription; pub mod widget; pub use bus::Bus; pub use dodrio; pub use element::Element; +pub use hasher::Hasher; pub use iced_core::{ Align, Background, Color, Command, Font, HorizontalAlignment, Length, VerticalAlignment, }; pub use style::Style; +pub use subscription::Subscription; pub use widget::*; /// An interactive web application. diff --git a/web/src/subscription.rs b/web/src/subscription.rs new file mode 100644 index 00000000..4638c8ab --- /dev/null +++ b/web/src/subscription.rs @@ -0,0 +1,19 @@ +//! Listen to external events in your application. +use crate::Hasher; + +/// A request to listen to external events. +/// +/// Besides performing async actions on demand with [`Command`], most +/// applications also need to listen to external events passively. +/// +/// A [`Subscription`] is normally provided to some runtime, like a [`Command`], +/// and it will generate events as long as the user keeps requesting it. +/// +/// For instance, you can use a [`Subscription`] to listen to a WebSocket +/// connection, keyboard presses, mouse events, time ticks, etc. +/// +/// [`Command`]: ../struct.Command.html +/// [`Subscription`]: struct.Subscription.html +pub type Subscription = iced_core::Subscription; + +pub use iced_core::subscription::Recipe; -- cgit From eb4f55c60b337ee389d18961cf9839a798ce2ca4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 18 Dec 2019 23:57:31 +0100 Subject: Check `iced` builds when targetting Wasm in CI --- .github/workflows/test.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f911303..8c5ded3a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ name: Test on: [push, pull_request] jobs: - all: + native: runs-on: ${{ matrix.os }} strategy: matrix: @@ -16,3 +16,14 @@ jobs: run: | cargo test --verbose --all cargo test --verbose --all --all-features + + web: + runs-on: ubuntu-latest + steps: + - uses: hecrj/setup-rust-action@v1 + with: + rust-version: stable + targets: wasm32-unknown-unknown + - uses: actions/checkout@master + - name: Run checks + run: cargo check --package iced --target wasm32-unknown-unknown -- cgit From 68c8ebcd775416d5eb8efa9c095bbe1d44d964ad Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 19 Dec 2019 00:09:19 +0100 Subject: Fix `web::Hasher` doc comment --- web/src/hasher.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/hasher.rs b/web/src/hasher.rs index 9ce2f7be..1a28a2f9 100644 --- a/web/src/hasher.rs +++ b/web/src/hasher.rs @@ -1,6 +1,6 @@ use std::collections::hash_map::DefaultHasher; -/// The hasher used to compare layouts. +/// The hasher used to compare subscriptions. #[derive(Debug)] pub struct Hasher(DefaultHasher); -- cgit