77//! The function MUST NOT ever write uninitialized bytes into `dest`,
88//! regardless of what value it returns.
99
10+ /// Declares this function as an external implementation of [`u32`](crate::u32).
11+ #[ cfg_attr( getrandom_extern_item_impls, eii( u32 ) ) ]
12+ pub ( crate ) fn inner_u32 ( ) -> Result < u32 , crate :: Error > {
13+ default_u32 ( )
14+ }
15+
16+ /// Declares this function as an external implementation of [`u64`](crate::u64).
17+ #[ cfg_attr( getrandom_extern_item_impls, eii( u64 ) ) ]
18+ pub ( crate ) fn inner_u64 ( ) -> Result < u64 , crate :: Error > {
19+ default_u64 ( )
20+ }
21+
22+ macro_rules! implementation {
23+ ( ) => {
24+ use $crate:: util:: { inner_u32 as default_u32, inner_u64 as default_u64} ;
25+
26+ /// Declares this function as an external implementation of [`fill_uninit`](crate::fill_uninit).
27+ #[ cfg_attr( getrandom_extern_item_impls, eii( fill_uninit) ) ]
28+ pub ( crate ) fn fill_inner(
29+ dest: & mut [ :: core:: mem:: MaybeUninit <u8 >] ,
30+ ) -> Result <( ) , $crate:: Error >;
31+ } ;
32+ ( $backend: ident) => {
33+ use $backend:: { inner_u32 as default_u32, inner_u64 as default_u64} ;
34+
35+ /// Declares this function as an external implementation of [`fill_uninit`](crate::fill_uninit).
36+ #[ cfg_attr( getrandom_extern_item_impls, eii( fill_uninit) ) ]
37+ pub ( crate ) fn fill_inner(
38+ dest: & mut [ :: core:: mem:: MaybeUninit <u8 >] ,
39+ ) -> Result <( ) , $crate:: Error > {
40+ $backend:: fill_inner( dest)
41+ }
42+ } ;
43+ }
44+
1045cfg_if ! {
1146 if #[ cfg( getrandom_backend = "custom" ) ] {
1247 mod custom;
13- pub use custom:: * ;
48+ implementation! ( custom) ;
1449 } else if #[ cfg( getrandom_backend = "linux_getrandom" ) ] {
1550 mod getrandom;
16- pub use getrandom:: * ;
51+ implementation! ( getrandom) ;
1752 } else if #[ cfg( getrandom_backend = "linux_raw" ) ] {
1853 mod linux_raw;
19- pub use linux_raw:: * ;
54+ implementation! ( linux_raw) ;
2055 } else if #[ cfg( getrandom_backend = "rdrand" ) ] {
2156 mod rdrand;
22- pub use rdrand:: * ;
57+ implementation! ( rdrand) ;
2358 } else if #[ cfg( getrandom_backend = "rndr" ) ] {
2459 mod rndr;
25- pub use rndr:: * ;
60+ implementation! ( rndr) ;
2661 } else if #[ cfg( getrandom_backend = "efi_rng" ) ] {
2762 mod efi_rng;
28- pub use efi_rng:: * ;
63+ implementation! ( efi_rng) ;
2964 } else if #[ cfg( getrandom_backend = "windows_legacy" ) ] {
3065 mod windows_legacy;
31- pub use windows_legacy:: * ;
66+ implementation! ( windows_legacy) ;
3267 } else if #[ cfg( getrandom_backend = "unsupported" ) ] {
3368 mod unsupported;
34- pub use unsupported:: * ;
69+ implementation! ( unsupported) ;
3570 } else if #[ cfg( all( target_os = "linux" , target_env = "" ) ) ] {
3671 mod linux_raw;
37- pub use linux_raw:: * ;
72+ implementation! ( linux_raw) ;
3873 } else if #[ cfg( target_os = "espidf" ) ] {
3974 mod esp_idf;
40- pub use esp_idf:: * ;
75+ implementation! ( esp_idf) ;
4176 } else if #[ cfg( any(
4277 target_os = "haiku" ,
4378 target_os = "redox" ,
4479 target_os = "nto" ,
4580 target_os = "aix" ,
4681 ) ) ] {
4782 mod use_file;
48- pub use use_file:: * ;
83+ implementation! ( use_file) ;
4984 } else if #[ cfg( any(
5085 target_os = "macos" ,
5186 target_os = "openbsd" ,
5287 target_os = "vita" ,
5388 target_os = "emscripten" ,
5489 ) ) ] {
5590 mod getentropy;
56- pub use getentropy:: * ;
91+ implementation! ( getentropy) ;
5792 } else if #[ cfg( any(
5893 // Rust supports Android API level 19 (KitKat) [0] and the next upgrade targets
5994 // level 21 (Lollipop) [1], while `getrandom(2)` was added only in
@@ -101,7 +136,7 @@ cfg_if! {
101136 ) ) ] {
102137 mod use_file;
103138 mod linux_android_with_fallback;
104- pub use linux_android_with_fallback:: * ;
139+ implementation! ( linux_android_with_fallback) ;
105140 } else if #[ cfg( any(
106141 target_os = "android" ,
107142 target_os = "linux" ,
@@ -115,57 +150,59 @@ cfg_if! {
115150 all( target_os = "horizon" , target_arch = "arm" ) ,
116151 ) ) ] {
117152 mod getrandom;
118- pub use getrandom:: * ;
153+ implementation! ( getrandom) ;
119154 } else if #[ cfg( target_os = "solaris" ) ] {
120155 mod solaris;
121- pub use solaris:: * ;
156+ implementation! ( solaris) ;
122157 } else if #[ cfg( target_os = "netbsd" ) ] {
123158 mod netbsd;
124- pub use netbsd:: * ;
159+ implementation! ( netbsd) ;
125160 } else if #[ cfg( target_os = "fuchsia" ) ] {
126161 mod fuchsia;
127- pub use fuchsia:: * ;
162+ implementation! ( fuchsia) ;
128163 } else if #[ cfg( any(
129164 target_os = "ios" ,
130165 target_os = "visionos" ,
131166 target_os = "watchos" ,
132167 target_os = "tvos" ,
133168 ) ) ] {
134169 mod apple_other;
135- pub use apple_other:: * ;
170+ implementation! ( apple_other) ;
136171 } else if #[ cfg( all( target_arch = "wasm32" , target_os = "wasi" ) ) ] {
137172 cfg_if! {
138173 if #[ cfg( target_env = "p1" ) ] {
139174 mod wasi_p1;
140- pub use wasi_p1:: * ;
175+ implementation! ( wasi_p1) ;
141176 } else {
142177 mod wasi_p2_3;
143- pub use wasi_p2_3:: * ;
178+ implementation! ( wasi_p2_3) ;
144179 }
145180 }
146181 } else if #[ cfg( target_os = "hermit" ) ] {
147182 mod hermit;
148- pub use hermit:: * ;
183+ implementation! ( hermit) ;
149184 } else if #[ cfg( target_os = "vxworks" ) ] {
150185 mod vxworks;
151- pub use vxworks:: * ;
186+ implementation! ( vxworks) ;
152187 } else if #[ cfg( target_os = "solid_asp3" ) ] {
153188 mod solid;
154- pub use solid:: * ;
189+ implementation! ( solid) ;
155190 } else if #[ cfg( all( windows, target_vendor = "win7" ) ) ] {
156191 mod windows_legacy;
157- pub use windows_legacy:: * ;
192+ implementation! ( windows_legacy) ;
158193 } else if #[ cfg( windows) ] {
159194 mod windows;
160- pub use windows:: * ;
195+ implementation! ( windows) ;
161196 } else if #[ cfg( all( target_arch = "x86_64" , target_env = "sgx" ) ) ] {
162197 mod rdrand;
163- pub use rdrand:: * ;
198+ implementation! ( rdrand) ;
164199 } else if #[ cfg( all( target_arch = "wasm32" , any( target_os = "unknown" , target_os = "none" ) ) ) ] {
165200 cfg_if! {
166201 if #[ cfg( feature = "wasm_js" ) ] {
167202 mod wasm_js;
168- pub use wasm_js:: * ;
203+ implementation!( wasm_js) ;
204+ } else if #[ cfg( getrandom_extern_item_impls) ] {
205+ implementation!( ) ;
169206 } else {
170207 compile_error!( concat!(
171208 "The wasm32-unknown-unknown targets are not supported by default; \
@@ -175,6 +212,8 @@ cfg_if! {
175212 ) ) ;
176213 }
177214 }
215+ } else if #[ cfg( getrandom_extern_item_impls) ] {
216+ implementation!( ) ;
178217 } else {
179218 compile_error!( concat!(
180219 "target is not supported. You may need to define a custom backend see: \
0 commit comments