Skip to content

Commit

Permalink
Replace instant with web-time
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Jun 1, 2023
1 parent 2ade772 commit dfc6cc5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Web: fix position of touch events to be relative to the canvas.
- On Web, fix `Window:::set_fullscreen` doing nothing when called outside the event loop but during
a transient activation.
- **Breaking:** On Web, `instant` now is replaced by `web_time`.

# 0.28.6

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ cfg_aliases = "0.1.1"
[dependencies]
bitflags = "1"
cursor-icon = "1.0.0"
instant = { version = "0.1", features = ["wasm-bindgen"] }
log = "0.4"
mint = { version = "0.5.6", optional = true }
once_cell = "1.12"
Expand Down Expand Up @@ -159,6 +158,7 @@ features = [
js-sys = "0.3"
wasm-bindgen = "0.2.45"
wasm-bindgen-futures = "0.4"
web-time = "0.2"

[target.'cfg(target_family = "wasm")'.dev-dependencies]
console_log = "1"
Expand Down
8 changes: 6 additions & 2 deletions examples/control_flow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#![allow(clippy::single_match)]

use std::{thread, time};
use std::thread;
#[cfg(not(wasm_platform))]
use std::time;
#[cfg(wasm_platform)]
use web_time as time;

use simple_logger::SimpleLogger;
use winit::{
Expand Down Expand Up @@ -102,7 +106,7 @@ fn main() {
Mode::Wait => control_flow.set_wait(),
Mode::WaitUntil => {
if !wait_cancelled {
control_flow.set_wait_until(instant::Instant::now() + WAIT_TIME);
control_flow.set_wait_until(time::Instant::now() + WAIT_TIME);
}
}
Mode::Poll => {
Expand Down
5 changes: 4 additions & 1 deletion examples/timer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#![allow(clippy::single_match)]

use instant::Instant;
use std::time::Duration;
#[cfg(not(wasm_platform))]
use std::time::Instant;
#[cfg(wasm_platform)]
use web_time::Instant;

use simple_logger::SimpleLogger;
use winit::{
Expand Down
5 changes: 4 additions & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
//!
//! [`EventLoop::run(...)`]: crate::event_loop::EventLoop::run
//! [`ControlFlow::WaitUntil`]: crate::event_loop::ControlFlow::WaitUntil
use instant::Instant;
use smol_str::SmolStr;
use std::path::PathBuf;
#[cfg(not(wasm_platform))]
use std::time::Instant;
#[cfg(wasm_platform)]
use web_time::Instant;

#[cfg(doc)]
use crate::window::Window;
Expand Down
5 changes: 4 additions & 1 deletion src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ use std::marker::PhantomData;
use std::ops::Deref;
use std::{error, fmt};

use instant::{Duration, Instant};
use once_cell::sync::OnceCell;
use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle};
#[cfg(not(wasm_platform))]
use std::time::{Duration, Instant};
#[cfg(wasm_platform)]
use web_time::{Duration, Instant};

use crate::{event::Event, monitor::MonitorHandle, platform_impl};

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/web/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::event::{Event, StartCause};
use crate::event_loop::ControlFlow;
use crate::window::WindowId;

use instant::{Duration, Instant};
use std::{
cell::RefCell,
clone::Clone,
Expand All @@ -12,6 +11,7 @@ use std::{
ops::Deref,
rc::{Rc, Weak},
};
use web_time::{Duration, Instant};

pub struct Shared<T: 'static>(Rc<Execution<T>>);

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/web/event_loop/state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::backend;
use crate::event_loop::ControlFlow;

use instant::Instant;
use web_time::Instant;

#[derive(Debug)]
pub enum State {
Expand Down

0 comments on commit dfc6cc5

Please sign in to comment.