File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -71,8 +71,31 @@ fn test_from_utf8() {
7171 println ! ( "{:?}" , std:: str :: from_utf8( content) . unwrap( ) ) ;
7272}
7373
74+ fn test_u64_array ( ) {
75+ #[ derive( Default ) ]
76+ #[ repr( align( 8 ) ) ]
77+ struct AlignToU64 < T > ( T ) ;
78+
79+ const BYTE_LEN : usize = std:: mem:: size_of :: < [ u64 ; 4 ] > ( ) ;
80+ type Data = AlignToU64 < [ u8 ; BYTE_LEN ] > ;
81+
82+ fn example ( data : & Data ) {
83+ let ( head, u64_arrays, tail) = unsafe { data. 0 . align_to :: < [ u64 ; 4 ] > ( ) } ;
84+
85+ assert ! ( head. is_empty( ) , "buffer was not aligned for 64-bit numbers" ) ;
86+ assert_eq ! ( u64_arrays. len( ) , 1 , "buffer was not long enough" ) ;
87+ assert ! ( tail. is_empty( ) , "buffer was too long" ) ;
88+
89+ let u64_array = & u64_arrays[ 0 ] ;
90+ let _val = u64_array[ 0 ] ; // make sure we can actually load this
91+ }
92+
93+ example ( & Data :: default ( ) ) ;
94+ }
95+
7496fn main ( ) {
7597 test_align_offset ( ) ;
7698 test_align_to ( ) ;
7799 test_from_utf8 ( ) ;
100+ test_u64_array ( ) ;
78101}
You can’t perform that action at this time.
0 commit comments