Commit 272f44a 1 parent 57b0630 commit 272f44a Copy full SHA for 272f44a
File tree 3 files changed +24
-4
lines changed
3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ appveyor = { repository = "rust-random/getrandom" }
18
18
members = [
19
19
" custom/dummy" ,
20
20
" custom/stdweb" ,
21
+ " custom/wasm-bindgen" ,
21
22
]
22
23
23
24
[dependencies ]
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " getrandom-wasm-bindgen"
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 wasm-bindgen"
8
+ documentation = " https://docs.rs/getrandom-bindgen"
9
+ repository = " https://github.com/rust-random/getrandom/tree/master/custom/bindgen"
10
+ categories = [" wasm" ]
11
+
12
+ [lib ]
13
+ crate-type = [" dylib" ]
14
+
15
+ [dependencies ]
16
+ getrandom = { path = " ../.." , features = [" custom" ] }
17
+ wasm-bindgen = " 0.2.29"
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 wasm-bindgen
10
- extern crate std ;
9
+ //! `getrandom` implementation for WASM via wasm-bindgen
10
+ #! [ cfg ( all ( target_arch = "wasm32" , target_os = "unknown" ) ) ]
11
11
12
12
use core:: cell:: RefCell ;
13
13
use core:: mem;
14
14
use std:: thread_local;
15
15
16
16
use wasm_bindgen:: prelude:: * ;
17
17
18
- use crate :: Error ;
18
+ use getrandom :: { register_custom_getrandom , Error } ;
19
19
20
20
#[ derive( Clone , Debug ) ]
21
21
enum RngSource {
@@ -29,7 +29,9 @@ thread_local!(
29
29
static RNG_SOURCE : RefCell <Option <RngSource >> = RefCell :: new( None ) ;
30
30
) ;
31
31
32
- pub fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
32
+ register_custom_getrandom ! ( getrandom_inner) ;
33
+
34
+ fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
33
35
assert_eq ! ( mem:: size_of:: <usize >( ) , 4 ) ;
34
36
35
37
RNG_SOURCE . with ( |f| {
You can’t perform that action at this time.
0 commit comments