This repository was archived by the owner on May 28, 2025. It is now read-only.
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 @@ -176,6 +176,18 @@ where
176176 }
177177}
178178
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+
179191#[ stable( feature = "try_from" , since = "1.34.0" ) ]
180192impl < ' a , T , const N : usize > TryFrom < & ' a [ T ] > for & ' a [ T ; N ] {
181193 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