Skip to content

Commit 87b3e03

Browse files
committed
Enable instant only for wasm32 targets
... and hide the dependency under a `time` module in `iced_native`
1 parent 7767241 commit 87b3e03

6 files changed

Lines changed: 19 additions & 6 deletions

File tree

native/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ debug = []
1414
twox-hash = { version = "1.5", default-features = false }
1515
unicode-segmentation = "1.6"
1616
num-traits = "0.2"
17-
instant = { version="0.1", features=["wasm-bindgen"] }
1817

1918
[dependencies.iced_core]
2019
version = "0.4"
@@ -28,3 +27,7 @@ features = ["thread-pool"]
2827
[dependencies.iced_style]
2928
version = "0.3"
3029
path = "../style"
30+
31+
[target.'cfg(target_arch = "wasm32")'.dependencies.instant]
32+
version = "0.1"
33+
features = ["wasm-bindgen"]

native/src/debug/basic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(missing_docs)]
2-
use std::{collections::VecDeque, time};
2+
use crate::time;
3+
4+
use std::collections::VecDeque;
35

46
/// A bunch of time measurements for debugging purposes.
57
#[derive(Debug)]

native/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub mod renderer;
4949
pub mod subscription;
5050
pub mod svg;
5151
pub mod text;
52+
pub mod time;
5253
pub mod touch;
5354
pub mod user_interface;
5455
pub mod widget;

native/src/mouse/click.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Track mouse clicks.
2+
use crate::time::Instant;
23
use crate::Point;
3-
use instant::Instant;
44

55
/// A mouse click.
66
#[derive(Debug, Clone, Copy)]

native/src/time.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Keep track of time, both in native and web platforms!
2+
3+
#[cfg(target_arch = "wasm32")]
4+
pub use instant::{Duration, Instant};
5+
6+
#[cfg(not(target_arch = "wasm32"))]
7+
pub use std::time::{Duration, Instant};

src/time.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! Listen and react to time.
2+
pub use crate::runtime::time::{Duration, Instant};
3+
24
use crate::Subscription;
35

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

0 commit comments

Comments
 (0)