1 //! This module defines a macro that lets you go from a raw pointer to a struct 2 //! to a raw pointer to a field of the struct. 3 4 macro_rules! generate_addr_of_methods { 5 ( 6 impl<$($gen:ident)*> $struct_name:ty {$( 7 $(#[$attrs:meta])* 8 $vis:vis unsafe fn $fn_name:ident(self: NonNull<Self>) -> NonNull<$field_type:ty> { 9 &self$(.$field_name:tt)+ 10 } 11 )*} 12 ) => { 13 impl<$($gen)*> $struct_name {$( 14 $(#[$attrs])* 15 $vis unsafe fn $fn_name(me: ::core::ptr::NonNull<Self>) -> ::core::ptr::NonNull<$field_type> { 16 let me = me.as_ptr(); 17 let field = ::std::ptr::addr_of_mut!((*me) $(.$field_name)+ ); 18 ::core::ptr::NonNull::new_unchecked(field) 19 } 20 )*} 21 }; 22 } 23