File tree 3 files changed +27
-5
lines changed
3 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ appveyor = { repository = "rust-random/getrandom" }
17
17
[workspace ]
18
18
members = [
19
19
" custom/dummy" ,
20
+ " custom/stdweb" ,
20
21
]
21
22
22
23
[dependencies ]
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " getrandom-stdweb"
3
+ version = " 0.1.0"
4
+ edition = " 2018"
5
+ authors = [" The Rand Project Developers" ]
6
+ license = " MIT OR Apache-2.0"
7
+ description = " Custom shim for using getrandom with stdweb"
8
+ documentation = " https://docs.rs/getrandom-stdweb"
9
+ repository = " https://github.com/rust-random/getrandom/tree/master/custom/stdweb"
10
+ categories = [" wasm" ]
11
+
12
+ [lib ]
13
+ crate-type = [" dylib" ]
14
+
15
+ [dependencies ]
16
+ getrandom = { path = " ../.." , features = [" custom" ] }
17
+ stdweb = " 0.4.18"
18
+ log = " 0.4"
Original file line number Diff line number Diff line change 6
6
// option. This file may not be copied, modified, or distributed
7
7
// except according to those terms.
8
8
9
- //! Implementation for WASM via stdweb
10
- extern crate std ;
9
+ //! `getrandom` implementation for WASM via stdweb
10
+ #! [ cfg ( all ( target_arch = "wasm32" , target_os = "unknown" ) ) ]
11
11
12
12
use core:: mem;
13
+ use std:: sync:: Once ;
13
14
15
+ use log:: error;
14
16
use stdweb:: js;
15
17
use stdweb:: unstable:: TryInto ;
16
18
use stdweb:: web:: error:: Error as WebError ;
17
19
18
- use crate :: Error ;
19
- use std:: sync:: Once ;
20
+ use getrandom:: { register_custom_getrandom, Error } ;
20
21
21
22
#[ derive( Clone , Copy , Debug ) ]
22
23
enum RngSource {
23
24
Browser ,
24
25
Node ,
25
26
}
26
27
27
- pub fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
28
+ register_custom_getrandom ! ( getrandom_inner) ;
29
+
30
+ fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
28
31
assert_eq ! ( mem:: size_of:: <usize >( ) , 4 ) ;
29
32
static ONCE : Once = Once :: new ( ) ;
30
33
static mut RNG_SOURCE : Result < RngSource , Error > = Ok ( RngSource :: Node ) ;
You can’t perform that action at this time.
0 commit comments