57
57
pub fn get ( & self , bit_offset : usize , bit_width : u8 ) -> u64 {
58
58
debug_assert ! ( bit_width <= 64 ) ;
59
59
debug_assert ! ( bit_offset / 8 < self . storage. as_ref( ) . len( ) ) ;
60
- debug_assert ! ( ( bit_offset + ( bit_width as usize ) ) / 8 <= self . storage. as_ref( ) . len( ) ) ;
60
+ debug_assert ! (
61
+ ( bit_offset + ( bit_width as usize ) ) / 8 <=
62
+ self . storage. as_ref( ) . len( )
63
+ ) ;
61
64
let mut val = 0 ;
62
65
for i in 0 ..( bit_width as usize ) {
63
66
if self . get_bit ( i + bit_offset) {
75
78
pub fn set ( & mut self , bit_offset : usize , bit_width : u8 , val : u64 ) {
76
79
debug_assert ! ( bit_width <= 64 ) ;
77
80
debug_assert ! ( bit_offset / 8 < self . storage. as_ref( ) . len( ) ) ;
78
- debug_assert ! ( ( bit_offset + ( bit_width as usize ) ) / 8 <= self . storage. as_ref( ) . len( ) ) ;
81
+ debug_assert ! (
82
+ ( bit_offset + ( bit_width as usize ) ) / 8 <=
83
+ self . storage. as_ref( ) . len( )
84
+ ) ;
79
85
for i in 0 ..( bit_width as usize ) {
80
86
let mask = 1 << i;
81
87
let val_bit_is_set = val & mask == mask;
@@ -89,28 +95,35 @@ where
89
95
}
90
96
}
91
97
#[ repr( C , packed( 4 ) ) ]
92
- #[ repr( align( 4 ) ) ]
93
98
#[ derive( Debug , Default , Copy , Clone ) ]
94
99
pub struct Test {
100
+ pub foo : u64 ,
95
101
pub _bitfield_1 : __BindgenBitfieldUnit < [ u8 ; 8usize ] , u64 > ,
96
102
}
97
103
#[ test]
98
104
fn bindgen_test_layout_Test ( ) {
99
105
assert_eq ! (
100
106
:: std:: mem:: size_of:: <Test >( ) ,
101
- 8usize ,
107
+ 16usize ,
102
108
concat!( "Size of: " , stringify!( Test ) )
103
109
) ;
104
110
assert_eq ! (
105
111
:: std:: mem:: align_of:: <Test >( ) ,
106
112
4usize ,
107
113
concat!( "Alignment of " , stringify!( Test ) )
108
114
) ;
115
+ assert_eq ! (
116
+ unsafe { & ( * ( :: std:: ptr:: null:: <Test >( ) ) ) . foo as * const _ as usize } ,
117
+ 0usize ,
118
+ concat!( "Offset of field: " , stringify!( Test ) , "::" , stringify!( foo) )
119
+ ) ;
109
120
}
110
121
impl Test {
111
122
#[ inline]
112
123
pub fn x ( & self ) -> u64 {
113
- unsafe { :: std:: mem:: transmute ( self . _bitfield_1 . get ( 0usize , 56u8 ) as u64 ) }
124
+ unsafe {
125
+ :: std:: mem:: transmute ( self . _bitfield_1 . get ( 0usize , 56u8 ) as u64 )
126
+ }
114
127
}
115
128
#[ inline]
116
129
pub fn set_x ( & mut self , val : u64 ) {
@@ -121,7 +134,9 @@ impl Test {
121
134
}
122
135
#[ inline]
123
136
pub fn y ( & self ) -> u64 {
124
- unsafe { :: std:: mem:: transmute ( self . _bitfield_1 . get ( 56usize , 8u8 ) as u64 ) }
137
+ unsafe {
138
+ :: std:: mem:: transmute ( self . _bitfield_1 . get ( 56usize , 8u8 ) as u64 )
139
+ }
125
140
}
126
141
#[ inline]
127
142
pub fn set_y ( & mut self , val : u64 ) {
@@ -131,9 +146,14 @@ impl Test {
131
146
}
132
147
}
133
148
#[ inline]
134
- pub fn new_bitfield_1 ( x : u64 , y : u64 ) -> __BindgenBitfieldUnit < [ u8 ; 8usize ] , u64 > {
135
- let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit < [ u8 ; 8usize ] , u64 > =
136
- Default :: default ( ) ;
149
+ pub fn new_bitfield_1 (
150
+ x : u64 ,
151
+ y : u64 ,
152
+ ) -> __BindgenBitfieldUnit < [ u8 ; 8usize ] , u64 > {
153
+ let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit <
154
+ [ u8 ; 8usize ] ,
155
+ u64 ,
156
+ > = Default :: default ( ) ;
137
157
__bindgen_bitfield_unit. set ( 0usize , 56u8 , {
138
158
let x: u64 = unsafe { :: std:: mem:: transmute ( x) } ;
139
159
x as u64
0 commit comments