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 @@ -189,6 +189,18 @@ where
189
189
}
190
190
}
191
191
192
+ #[ stable( feature = "try_from_mut_slice_to_array" , since = "1.59.0" ) ]
193
+ impl < T , const N : usize > TryFrom < & mut [ T ] > for [ T ; N ]
194
+ where
195
+ T : Copy ,
196
+ {
197
+ type Error = TryFromSliceError ;
198
+
199
+ fn try_from ( slice : & mut [ T ] ) -> Result < [ T ; N ] , TryFromSliceError > {
200
+ <Self >:: try_from ( & * slice)
201
+ }
202
+ }
203
+
192
204
#[ stable( feature = "try_from" , since = "1.34.0" ) ]
193
205
impl < ' a , T , const N : usize > TryFrom < & ' a [ T ] > for & ' a [ T ; N ] {
194
206
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