File tree 5 files changed +19
-6
lines changed
5 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ uuid = { version = "1.1", optional = true }
24
24
postgres-types = { version = " 0.2.6" , optional = true }
25
25
bytes = { version = " 1.4.0" , optional = true }
26
26
27
+ [target .wasm32-unknown-unknown .dependencies ]
28
+ getrandom = { version = " 0.2" , features = [" js" ] }
29
+ web-time = " 1"
30
+
27
31
[dev-dependencies ]
28
32
bencher = " 0.1"
29
33
serde_derive = " 1.0"
Original file line number Diff line number Diff line change @@ -42,8 +42,7 @@ impl Generator {
42
42
/// assert!(ulid1 < ulid2);
43
43
/// ```
44
44
pub fn generate ( & mut self ) -> Result < Ulid , MonotonicError > {
45
- let now = SystemTime :: now ( ) ;
46
- self . generate_from_datetime ( now)
45
+ self . generate_from_datetime ( crate :: time_utils:: now ( ) )
47
46
}
48
47
49
48
/// Generate a new Ulid matching the given DateTime.
@@ -91,8 +90,7 @@ impl Generator {
91
90
where
92
91
R : rand:: Rng + ?Sized ,
93
92
{
94
- let now = SystemTime :: now ( ) ;
95
- self . generate_from_datetime_with_source ( now, source)
93
+ self . generate_from_datetime_with_source ( crate :: time_utils:: now ( ) , source)
96
94
}
97
95
98
96
/// Generate a new monotonic increasing Ulid with the given source matching the given DateTime
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ mod postgres;
44
44
pub mod serde;
45
45
#[ cfg( feature = "std" ) ]
46
46
mod time;
47
+ #[ cfg( feature = "std" ) ]
48
+ mod time_utils;
47
49
#[ cfg( feature = "uuid" ) ]
48
50
mod uuid;
49
51
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ impl Ulid {
11
11
/// let my_ulid = Ulid::new();
12
12
/// ```
13
13
pub fn new ( ) -> Ulid {
14
- Ulid :: from_datetime ( SystemTime :: now ( ) )
14
+ Ulid :: from_datetime ( crate :: time_utils :: now ( ) )
15
15
}
16
16
17
17
/// Creates a new Ulid using data from the given random number generator
@@ -25,7 +25,7 @@ impl Ulid {
25
25
/// let ulid = Ulid::with_source(&mut rng);
26
26
/// ```
27
27
pub fn with_source < R : rand:: Rng > ( source : & mut R ) -> Ulid {
28
- Ulid :: from_datetime_with_source ( SystemTime :: now ( ) , source)
28
+ Ulid :: from_datetime_with_source ( crate :: time_utils :: now ( ) , source)
29
29
}
30
30
31
31
/// Creates a new Ulid with the given datetime
Original file line number Diff line number Diff line change
1
+ pub ( crate ) fn now ( ) -> std:: time:: SystemTime {
2
+ #[ cfg( target_arch = "wasm32" ) ]
3
+ {
4
+ use web_time:: web:: SystemTimeExt ;
5
+ return web_time:: SystemTime :: now ( ) . to_std ( ) ;
6
+ }
7
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
8
+ return std:: time:: SystemTime :: now ( ) ;
9
+ }
You can’t perform that action at this time.
0 commit comments