File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,18 @@ where
189189 }
190190}
191191
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+
192204#[ stable( feature = "try_from" , since = "1.34.0" ) ]
193205impl < ' a , T , const N : usize > TryFrom < & ' a [ T ] > for & ' a [ T ; N ] {
194206 type Error = TryFromSliceError ;
Original file line number Diff line number Diff line change @@ -28,11 +28,22 @@ fn array_try_from() {
2828 ( $( $N: expr) +) => {
2929 $( {
3030 type Array = [ u8 ; $N] ;
31- let array: Array = [ 0 ; $N] ;
31+ let mut array: Array = [ 0 ; $N] ;
3232 let slice: & [ u8 ] = & array[ ..] ;
3333
3434 let result = <& Array >:: try_from( slice) ;
3535 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( ) ) ;
3647 } ) +
3748 }
3849 }
You can’t perform that action at this time.
0 commit comments