File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,18 @@ where
176
176
}
177
177
}
178
178
179
+ #[ stable( feature = "try_from_mut_slice_to_array" , since = "1.57.0" ) ]
180
+ impl < T , const N : usize > TryFrom < & mut [ T ] > for [ T ; N ]
181
+ where
182
+ T : Copy ,
183
+ {
184
+ type Error = TryFromSliceError ;
185
+
186
+ fn try_from ( slice : & mut [ T ] ) -> Result < [ T ; N ] , TryFromSliceError > {
187
+ <Self >:: try_from ( slice. as_ref ( ) )
188
+ }
189
+ }
190
+
179
191
#[ stable( feature = "try_from" , since = "1.34.0" ) ]
180
192
impl < ' a , T , const N : usize > TryFrom < & ' a [ T ] > for & ' a [ T ; N ] {
181
193
type Error = TryFromSliceError ;
Original file line number Diff line number Diff line change @@ -28,11 +28,22 @@ fn array_try_from() {
28
28
( $( $N: expr) +) => {
29
29
$( {
30
30
type Array = [ u8 ; $N] ;
31
- let array: Array = [ 0 ; $N] ;
31
+ let mut array: Array = [ 0 ; $N] ;
32
32
let slice: & [ u8 ] = & array[ ..] ;
33
33
34
34
let result = <& Array >:: try_from( slice) ;
35
35
assert_eq!( & array, result. unwrap( ) ) ;
36
+
37
+ let result = <Array >:: try_from( slice) ;
38
+ assert_eq!( & array, & result. unwrap( ) ) ;
39
+
40
+ let mut_slice: & mut [ u8 ] = & mut array[ ..] ;
41
+ let result = <& mut Array >:: try_from( mut_slice) ;
42
+ assert_eq!( & [ 0 ; $N] , result. unwrap( ) ) ;
43
+
44
+ let mut_slice: & mut [ u8 ] = & mut array[ ..] ;
45
+ let result = <Array >:: try_from( mut_slice) ;
46
+ assert_eq!( & array, & result. unwrap( ) ) ;
36
47
} ) +
37
48
}
38
49
}
You can’t perform that action at this time.
0 commit comments