@@ -82,20 +82,20 @@ macro_rules! impl_has_list_links_self_ptr {
8282 ( $( impl $( { $( $generics: tt) * } ) ?
8383 HasSelfPtr <$item_type: ty $( , $id: tt) ?>
8484 for $self: ty
85- { self . $field: ident }
85+ { self $ ( . $field: ident) * }
8686 ) * ) => { $(
8787 // SAFETY: The implementation of `raw_get_list_links` only compiles if the field has the
8888 // right type.
8989 unsafe impl $( <$( $generics) * >) ? $crate:: list:: HasSelfPtr <$item_type $( , $id) ?> for $self { }
9090
9191 unsafe impl $( <$( $generics) * >) ? $crate:: list:: HasListLinks $( <$id>) ? for $self {
92- const OFFSET : usize = :: core:: mem:: offset_of!( Self , $field) as usize ;
92+ const OFFSET : usize = :: core:: mem:: offset_of!( Self , $( $ field) . * ) as usize ;
9393
9494 #[ inline]
9595 unsafe fn raw_get_list_links( ptr: * mut Self ) -> * mut $crate:: list:: ListLinks $( <$id>) ? {
9696 // SAFETY: The caller promises that the pointer is not dangling.
9797 let ptr: * mut $crate:: list:: ListLinksSelfPtr <$item_type $( , $id) ?> =
98- unsafe { :: core:: ptr:: addr_of_mut!( ( * ptr) . $field) } ;
98+ unsafe { :: core:: ptr:: addr_of_mut!( ( * ptr) $ ( . $field) * ) } ;
9999 ptr. cast( )
100100 }
101101 }
@@ -109,6 +109,96 @@ pub use impl_has_list_links_self_ptr;
109109/// implement that trait.
110110///
111111/// [`ListItem`]: crate::list::ListItem
112+ ///
113+ /// # Examples
114+ ///
115+ /// ```
116+ /// #[pin_data]
117+ /// struct SimpleListItem {
118+ /// value: u32,
119+ /// #[pin]
120+ /// links: kernel::list::ListLinks,
121+ /// }
122+ ///
123+ /// kernel::list::impl_has_list_links! {
124+ /// impl HasListLinks<0> for SimpleListItem { self.links }
125+ /// }
126+ ///
127+ /// kernel::list::impl_list_arc_safe! {
128+ /// impl ListArcSafe<0> for SimpleListItem { untracked; }
129+ /// }
130+ ///
131+ /// kernel::list::impl_list_item! {
132+ /// impl ListItem<0> for SimpleListItem { using ListLinks; }
133+ /// }
134+ ///
135+ /// struct ListLinksHolder {
136+ /// inner: kernel::list::ListLinks,
137+ /// }
138+ ///
139+ /// #[pin_data]
140+ /// struct ComplexListItem<T, U> {
141+ /// value: Result<T, U>,
142+ /// #[pin]
143+ /// links: ListLinksHolder,
144+ /// }
145+ ///
146+ /// kernel::list::impl_has_list_links! {
147+ /// impl{T, U} HasListLinks<0> for ComplexListItem<T, U> { self.links.inner }
148+ /// }
149+ ///
150+ /// kernel::list::impl_list_arc_safe! {
151+ /// impl{T, U} ListArcSafe<0> for ComplexListItem<T, U> { untracked; }
152+ /// }
153+ ///
154+ /// kernel::list::impl_list_item! {
155+ /// impl{T, U} ListItem<0> for ComplexListItem<T, U> { using ListLinks; }
156+ /// }
157+ /// ```
158+ ///
159+ /// ```
160+ /// #[pin_data]
161+ /// struct SimpleListItem {
162+ /// value: u32,
163+ /// #[pin]
164+ /// links: kernel::list::ListLinksSelfPtr<SimpleListItem>,
165+ /// }
166+ ///
167+ /// kernel::list::impl_list_arc_safe! {
168+ /// impl ListArcSafe<0> for SimpleListItem { untracked; }
169+ /// }
170+ ///
171+ /// kernel::list::impl_has_list_links_self_ptr! {
172+ /// impl HasSelfPtr<SimpleListItem> for SimpleListItem { self.links }
173+ /// }
174+ ///
175+ /// kernel::list::impl_list_item! {
176+ /// impl ListItem<0> for SimpleListItem { using ListLinksSelfPtr; }
177+ /// }
178+ ///
179+ /// struct ListLinksSelfPtrHolder<T, U> {
180+ /// inner: kernel::list::ListLinksSelfPtr<ComplexListItem<T, U>>,
181+ /// }
182+ ///
183+ /// #[pin_data]
184+ /// struct ComplexListItem<T, U> {
185+ /// value: Result<T, U>,
186+ /// #[pin]
187+ /// links: ListLinksSelfPtrHolder<T, U>,
188+ /// }
189+ ///
190+ /// kernel::list::impl_list_arc_safe! {
191+ /// impl{T, U} ListArcSafe<0> for ComplexListItem<T, U> { untracked; }
192+ /// }
193+ ///
194+ /// kernel::list::impl_has_list_links_self_ptr! {
195+ /// impl{T, U} HasSelfPtr<ComplexListItem<T, U>> for ComplexListItem<T, U> { self.links.inner }
196+ /// }
197+ ///
198+ /// kernel::list::impl_list_item! {
199+ /// impl{T, U} ListItem<0> for ComplexListItem<T, U> { using ListLinksSelfPtr; }
200+ /// }
201+ /// ```
112202#[ macro_export]
113203macro_rules! impl_list_item {
114204 (
0 commit comments