Skip to content

Commit

Permalink
Enable instant only for wasm32 targets
Browse files Browse the repository at this point in the history
... and hide the dependency under a `time` module in `iced_native`
  • Loading branch information
hecrj committed Jan 28, 2022
1 parent 7767241 commit 87b3e03
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ debug = []
twox-hash = { version = "1.5", default-features = false }
unicode-segmentation = "1.6"
num-traits = "0.2"
instant = { version="0.1", features=["wasm-bindgen"] }

[dependencies.iced_core]
version = "0.4"
Expand All @@ -28,3 +27,7 @@ features = ["thread-pool"]
[dependencies.iced_style]
version = "0.3"
path = "../style"

[target.'cfg(target_arch = "wasm32")'.dependencies.instant]
version = "0.1"
features = ["wasm-bindgen"]
4 changes: 3 additions & 1 deletion native/src/debug/basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(missing_docs)]
use std::{collections::VecDeque, time};
use crate::time;

use std::collections::VecDeque;

/// A bunch of time measurements for debugging purposes.
#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub mod renderer;
pub mod subscription;
pub mod svg;
pub mod text;
pub mod time;
pub mod touch;
pub mod user_interface;
pub mod widget;
Expand Down
2 changes: 1 addition & 1 deletion native/src/mouse/click.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Track mouse clicks.
use crate::time::Instant;
use crate::Point;
use instant::Instant;

/// A mouse click.
#[derive(Debug, Clone, Copy)]
Expand Down
7 changes: 7 additions & 0 deletions native/src/time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Keep track of time, both in native and web platforms!
#[cfg(target_arch = "wasm32")]
pub use instant::{Duration, Instant};

#[cfg(not(target_arch = "wasm32"))]
pub use std::time::{Duration, Instant};
6 changes: 3 additions & 3 deletions src/time.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Listen and react to time.
pub use crate::runtime::time::{Duration, Instant};

use crate::Subscription;

/// Returns a [`Subscription`] that produces messages at a set interval.
///
/// The first message is produced after a `duration`, and then continues to
/// produce more messages every `duration` after that.
pub fn every(
duration: std::time::Duration,
) -> Subscription<std::time::Instant> {
pub fn every(duration: Duration) -> Subscription<Instant> {
iced_futures::time::every(duration)
}

0 comments on commit 87b3e03

Please sign in to comment.