@@ -60,10 +60,21 @@ unsafe fn rndr_fill(dest: &mut [MaybeUninit<u8>]) -> Option<()> {
60
60
Some ( ( ) )
61
61
}
62
62
63
+ #[ cfg( target_feature = "rand" ) ]
63
64
fn is_rndr_available ( ) -> bool {
65
+ true
66
+ }
67
+
68
+ #[ cfg( not( target_feature = "rand" ) ) ]
69
+ fn is_rndr_available ( ) -> bool {
70
+ #[ path = "../lazy.rs" ]
71
+ mod lazy;
72
+ static RNDR_GOOD : lazy:: LazyBool = lazy:: LazyBool :: new ( ) ;
73
+
64
74
cfg_if:: cfg_if! {
65
- if #[ cfg( target_feature = "rand" ) ] {
66
- true
75
+ if #[ cfg( feature = "std" ) ] {
76
+ extern crate std;
77
+ RNDR_GOOD . unsync_init( || std:: arch:: is_aarch64_feature_detected!( "rand" ) )
67
78
} else if #[ cfg( target_os = "linux" ) ] {
68
79
/// Check whether FEAT_RNG is available on the system
69
80
///
@@ -87,14 +98,7 @@ fn is_rndr_available() -> bool {
87
98
( id_aa64isar0 >> 60 ) & 0xf >= 1
88
99
}
89
100
90
- #[ path = "../lazy.rs" ] mod lazy;
91
- static RNDR_GOOD : lazy:: LazyBool = lazy:: LazyBool :: new( ) ;
92
101
RNDR_GOOD . unsync_init( mrs_check)
93
- } else if #[ cfg( feature = "std" ) ] {
94
- extern crate std;
95
- #[ path = "../lazy.rs" ] mod lazy;
96
- static RNDR_GOOD : lazy:: LazyBool = lazy:: LazyBool :: new( ) ;
97
- RNDR_GOOD . unsync_init( || std:: arch:: is_aarch64_feature_detected!( "rand" ) )
98
102
} else {
99
103
compile_error!(
100
104
"RNDR `no_std` runtime detection is currently supported only on Linux targets. \
@@ -105,32 +109,29 @@ fn is_rndr_available() -> bool {
105
109
}
106
110
107
111
pub fn inner_u32 ( ) -> Result < u32 , Error > {
108
- if is_rndr_available ( ) {
109
- // SAFETY: after this point, we know the `rand` target feature is enabled
110
- let res = unsafe { rndr ( ) } ;
111
- res. map ( truncate) . ok_or ( Error :: RNDR_FAILURE )
112
- } else {
113
- Err ( Error :: RNDR_NOT_AVAILABLE )
112
+ if !is_rndr_available ( ) {
113
+ return Err ( Error :: RNDR_NOT_AVAILABLE ) ;
114
114
}
115
+ // SAFETY: after this point, we know the `rand` target feature is enabled
116
+ let res = unsafe { rndr ( ) } ;
117
+ res. map ( truncate) . ok_or ( Error :: RNDR_FAILURE )
115
118
}
116
119
117
120
pub fn inner_u64 ( ) -> Result < u64 , Error > {
118
- if is_rndr_available ( ) {
119
- // SAFETY: after this point, we know the `rand` target feature is enabled
120
- let res = unsafe { rndr ( ) } ;
121
- res. ok_or ( Error :: RNDR_FAILURE )
122
- } else {
123
- Err ( Error :: RNDR_NOT_AVAILABLE )
121
+ if !is_rndr_available ( ) {
122
+ return Err ( Error :: RNDR_NOT_AVAILABLE ) ;
124
123
}
124
+ // SAFETY: after this point, we know the `rand` target feature is enabled
125
+ let res = unsafe { rndr ( ) } ;
126
+ res. ok_or ( Error :: RNDR_FAILURE )
125
127
}
126
128
127
129
pub fn fill_inner ( dest : & mut [ MaybeUninit < u8 > ] ) -> Result < ( ) , Error > {
128
- if is_rndr_available ( ) {
129
- // SAFETY: after this point, we know the `rand` target feature is enabled
130
- unsafe { rndr_fill ( dest) . ok_or ( Error :: RNDR_FAILURE ) }
131
- } else {
132
- Err ( Error :: RNDR_NOT_AVAILABLE )
130
+ if !is_rndr_available ( ) {
131
+ return Err ( Error :: RNDR_NOT_AVAILABLE ) ;
133
132
}
133
+ // SAFETY: after this point, we know the `rand` target feature is enabled
134
+ unsafe { rndr_fill ( dest) . ok_or ( Error :: RNDR_FAILURE ) }
134
135
}
135
136
136
137
impl Error {
0 commit comments