Skip to content

Commit b2e54a6

Browse files
committed
Add support for nested map_field operations
1 parent 47660af commit b2e54a6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/volatile_ptr/macros.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
/// ```
3333
#[macro_export]
3434
macro_rules! map_field {
35-
($volatile:ident.$place:ident) => {{
35+
($volatile:ident.$($place:ident).+) => {{
3636
// Simulate creating a reference to the field. This is done to make
3737
// sure that the field is not potentially unaligned. The body of the
3838
// if statement will never be executed, so it can never cause any UB.
3939
if false {
40-
let _ref_to_field = &(unsafe { &*$volatile.as_raw_ptr().as_ptr() }).$place;
40+
let _ref_to_field = &(unsafe { &*$volatile.as_raw_ptr().as_ptr() }).$($place).+;
4141
}
4242

4343
unsafe {
4444
$volatile.map(|ptr| {
45-
core::ptr::NonNull::new(core::ptr::addr_of_mut!((*ptr.as_ptr()).$place)).unwrap()
45+
core::ptr::NonNull::new(core::ptr::addr_of_mut!((*ptr.as_ptr()).$($place).+)).unwrap()
4646
})
4747
}
4848
}};

0 commit comments

Comments
 (0)