Add support for Instant for wasm32.
This commit is contained in:
parent
ae6d5e13a9
commit
2a73841549
@ -63,3 +63,6 @@ version = "0.3.2"
|
||||
default-features = false
|
||||
features = ["compile-time-rng"]
|
||||
optional = true
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
instant= "0.1.4" # WASM implementation of std::time::Instant
|
||||
|
@ -27,6 +27,10 @@ use crate::stdlib::{
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use crate::stdlib::time::Instant;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use instant::Instant;
|
||||
|
||||
/// Trait to represent any type.
|
||||
///
|
||||
/// Currently, `Variant` is not `Send` nor `Sync`, so it can practically be any type.
|
||||
|
@ -33,7 +33,6 @@ pub use pkg_std::StandardPackage;
|
||||
pub use string_basic::BasicStringPackage;
|
||||
pub use string_more::MoreStringPackage;
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use time_basic::BasicTimePackage;
|
||||
|
||||
/// Trait that all packages must implement.
|
||||
|
@ -6,7 +6,6 @@ use super::math_basic::BasicMathPackage;
|
||||
use super::pkg_core::CorePackage;
|
||||
use super::string_more::MoreStringPackage;
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use super::time_basic::BasicTimePackage;
|
||||
|
||||
use crate::def_package;
|
||||
@ -19,7 +18,6 @@ def_package!(crate:StandardPackage:"_Standard_ package containing all built-in f
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
BasicMapPackage::init(lib);
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
BasicTimePackage::init(lib);
|
||||
MoreStringPackage::init(lib);
|
||||
});
|
||||
|
@ -1,5 +1,4 @@
|
||||
#![cfg(not(target_arch = "wasm32"))]
|
||||
|
||||
#![cfg(not(feature = "no_std"))]
|
||||
use super::logic::{eq, gt, gte, lt, lte, ne};
|
||||
use super::math_basic::MAX_INT;
|
||||
|
||||
@ -9,13 +8,15 @@ use crate::parser::INT;
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::token::Position;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use crate::stdlib::time::Instant;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use instant::Instant;
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
use crate::parser::FLOAT;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
def_package!(crate:BasicTimePackage:"Basic timing utilities.", lib, {
|
||||
// Register date/time functions
|
||||
lib.set_fn_0("timestamp", || Ok(Instant::now()));
|
||||
|
Loading…
Reference in New Issue
Block a user