Skip to content

Commit

Permalink
Deprecated the now feature flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmartindale committed Oct 6, 2021
1 parent de92ac1 commit 3c3b848
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ replacement for `std::time::Instant` that works on WASM too. This defines the ty
Note that even if the **stdweb** or **wasm-bindgen** feature is enabled, this crate will continue to rely on `std::time::Instant`
as long as you are not targeting wasm32. This allows for portable code that will work on both native and WASM platforms.

### The feature `now`.
By enabling the feature `now` the function `instant::now()` will be exported and will either:
This crate also exports the function `instant::now()` which returns a representation of the current time as an `f64`, expressed in milliseconds, in a platform-agnostic way. `instant::now()` will either:

* Call `performance.now()` when compiling for a WASM platform with the features **stdweb** or **wasm-bindgen** enabled, or using a custom javascript function.
* Call `time::precise_time_s() * 1000.0` otherwise.
* Return the time elapsed since the *Unix Epoch* on *native*, *non-WASM* platforms.

The result is expressed in milliseconds.
*Note*: The old feature, `now`, has been deprecated. `instant::now()` is always exported and the `now` feature flag no longer has any effect. It remains listed in `Cargo.toml` to avoid introducing breaking changes and may be removed in future versions.

## Examples
### Using `instant` for a native platform.
Expand Down Expand Up @@ -99,15 +98,15 @@ fn my_function() {

-----

### Using the feature `now`.
### Using `instant::now()`
_Cargo.toml_:
```toml
[features]
stdweb = [ "instant/stdweb" ]
wasm-bindgen = [ "instant/wasm-bindgen" ]

[dependencies]
instant = { version = "0.1", features = [ "now" ] }
instant = "0.1"
```

_lib.rs_:
Expand All @@ -124,7 +123,7 @@ fn my_function() {
_Cargo.toml_:
```toml
[dependencies]
instant = { version = "0.", features = [ "now" ] }
instant = "0.1"
```

_lib.rs_:
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ cfg_if::cfg_if! {

mod wasm;
pub use wasm::Instant;
#[cfg(feature = "now")]
pub use crate::wasm::now;
} else {
mod native;
pub use native::Instant;
#[cfg(feature = "now")]
pub use native::now;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/native.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub type Instant = std::time::Instant;

/// The current time, expressed in milliseconds since the Unix Epoch.
#[cfg(feature = "now")]
pub fn now() -> f64 {
std::time::SystemTime::now().duration_since(std::time::SystemTime::UNIX_EPOCH)
.expect("System clock was before 1970.")
Expand Down

0 comments on commit 3c3b848

Please sign in to comment.