Skip to content

Commit 73e154b

Browse files
authored
Merge pull request #50 from rust-osdev/nested-map_field
Add support for nested `map_field` operations
2 parents 9c53163 + b2e54a6 commit 73e154b

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
@@ -30,17 +30,17 @@
3030
/// ```
3131
#[macro_export]
3232
macro_rules! map_field {
33-
($volatile:ident.$place:ident) => {{
33+
($volatile:ident.$($place:ident).+) => {{
3434
// Simulate creating a reference to the field. This is done to make
3535
// sure that the field is not potentially unaligned. The body of the
3636
// if statement will never be executed, so it can never cause any UB.
3737
if false {
38-
let _ref_to_field = &(unsafe { &*$volatile.as_raw_ptr().as_ptr() }).$place;
38+
let _ref_to_field = &(unsafe { &*$volatile.as_raw_ptr().as_ptr() }).$($place).+;
3939
}
4040

4141
unsafe {
4242
$volatile.map(|ptr| {
43-
core::ptr::NonNull::new(core::ptr::addr_of_mut!((*ptr.as_ptr()).$place)).unwrap()
43+
core::ptr::NonNull::new(core::ptr::addr_of_mut!((*ptr.as_ptr()).$($place).+)).unwrap()
4444
})
4545
}
4646
}};

0 commit comments

Comments
 (0)