9
9
#![ no_std]
10
10
#![ no_main]
11
11
12
- use core:: mem:: size_of;
12
+ use core:: { mem:: size_of, usize } ;
13
13
use drv_lpc55_syscon_api:: Syscon ;
14
14
use drv_rng_api:: RngError ;
15
15
use idol_runtime:: { ClientError , NotificationHandler , RequestError } ;
@@ -33,17 +33,14 @@ where
33
33
T : SeedableRng ,
34
34
{
35
35
fn new ( mut reseeder : Lpc55Rng , threshold : usize ) -> Result < Self , Error > {
36
- use :: core:: usize:: MAX ;
37
-
38
- let threshold = if threshold == 0 { MAX } else { threshold } ;
39
-
40
- // try_trait_v2 is still experimental
41
- let inner = match T :: from_rng ( & mut reseeder) {
42
- Ok ( rng) => rng,
43
- Err ( err) => return Err ( err) ,
36
+ let threshold = if threshold == 0 {
37
+ usize:: MAX
38
+ } else {
39
+ threshold
44
40
} ;
41
+
45
42
Ok ( ReseedingRng {
46
- inner,
43
+ inner : T :: from_rng ( & mut reseeder ) ? ,
47
44
reseeder,
48
45
threshold,
49
46
bytes_until_reseed : threshold,
68
65
fn try_fill_bytes ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
69
66
let num_bytes = dest. len ( ) ;
70
67
if num_bytes >= self . bytes_until_reseed || num_bytes >= self . threshold {
71
- // try_trait_v2 is still experimental
72
- self . inner = match T :: from_rng ( & mut self . reseeder ) {
73
- Ok ( rng) => rng,
74
- Err ( e) => return Err ( e) ,
75
- } ;
68
+ self . inner = T :: from_rng ( & mut self . reseeder ) ?;
76
69
self . bytes_until_reseed = self . threshold ;
77
70
} else {
78
71
self . bytes_until_reseed -= num_bytes;
0 commit comments