@@ -26,21 +26,20 @@ where
26
26
type Error = Error ;
27
27
28
28
fn upgrade ( self ) -> Result < ModulusSwitchNoiseReductionKey < InputScalar > , Self :: Error > {
29
- let modulus_switch_zeros = & self . modulus_switch_zeros as & dyn Any ;
29
+ let modulus_switch_zeros: Box < dyn Any > = Box :: new ( self . modulus_switch_zeros ) ;
30
30
31
31
// Keys from previous versions where only stored as u64, we check if the destination
32
32
// key is also u64 or we return an error
33
33
Ok ( ModulusSwitchNoiseReductionKey {
34
- modulus_switch_zeros : modulus_switch_zeros
35
- . downcast_ref :: < LweCiphertextListOwned < InputScalar > > ( )
36
- . ok_or_else ( | | {
34
+ modulus_switch_zeros : * modulus_switch_zeros
35
+ . downcast :: < LweCiphertextListOwned < InputScalar > > ( )
36
+ . map_err ( |_ | {
37
37
Error :: new ( format ! (
38
38
"Expected u64 as InputScalar while upgrading \
39
39
ModulusSwitchNoiseReductionKey, got {}",
40
40
std:: any:: type_name:: <InputScalar >( ) ,
41
41
) )
42
- } ) ?
43
- . clone ( ) ,
42
+ } ) ?,
44
43
ms_bound : self . ms_bound ,
45
44
ms_r_sigma_factor : self . ms_r_sigma_factor ,
46
45
ms_input_variance : self . ms_input_variance ,
@@ -73,21 +72,20 @@ where
73
72
type Error = Error ;
74
73
75
74
fn upgrade ( self ) -> Result < CompressedModulusSwitchNoiseReductionKey < InputScalar > , Self :: Error > {
76
- let modulus_switch_zeros = & self . modulus_switch_zeros as & dyn Any ;
75
+ let modulus_switch_zeros: Box < dyn Any > = Box :: new ( self . modulus_switch_zeros ) ;
77
76
78
77
// Keys from previous versions where only stored as u64, we check if the destination
79
78
// key is also u64 or we return an error
80
79
Ok ( CompressedModulusSwitchNoiseReductionKey {
81
- modulus_switch_zeros : modulus_switch_zeros
82
- . downcast_ref :: < SeededLweCiphertextListOwned < InputScalar > > ( )
83
- . ok_or_else ( | | {
80
+ modulus_switch_zeros : * modulus_switch_zeros
81
+ . downcast :: < SeededLweCiphertextListOwned < InputScalar > > ( )
82
+ . map_err ( |_ | {
84
83
Error :: new ( format ! (
85
84
"Expected u64 as InputScalar while upgrading \
86
85
CompressedModulusSwitchNoiseReductionKey, got {}",
87
86
std:: any:: type_name:: <InputScalar >( ) ,
88
87
) )
89
- } ) ?
90
- . clone ( ) ,
88
+ } ) ?,
91
89
ms_bound : self . ms_bound ,
92
90
ms_r_sigma_factor : self . ms_r_sigma_factor ,
93
91
ms_input_variance : self . ms_input_variance ,
0 commit comments