Messages in this thread | | | Date | Thu, 18 May 2023 11:51:40 -0300 | From | Martin Rodriguez Reboredo <> | Subject | Re: [PATCH v1 2/7] rust: add offset_of! macro |
| |
On 5/17/23 17:31, Alice Ryhl wrote: > From: Wedson Almeida Filho <walmeida@microsoft.com> > > This macro is used to compute the offset of a field in a struct. > > This commit enables two unstable features that are necessary for using > the macro in a constant. However, this is not a problem as the macro > will become available from the Rust standard library soon [1]. The > unstable features can be disabled again once that happens. > > The macro in this patch does not support sub-fields. That is, you cannot > write `offset_of!(MyStruct, field.sub_field)` to get the offset of > `sub_field` with `field`'s type being a struct with a field called > `sub_field`. This is because `field` might be a `Box<SubStruct>`, which > means that you would be trying to compute the offset to something in an > entirely different allocation. There's no easy way to fix the current > macro to support subfields, but the version being added to the standard > library should support it, so the limitation is temporary and not a big > deal. > > Link: https://github.com/rust-lang/rust/issues/106655 [1] > Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com> > Co-developed-by: Alice Ryhl <aliceryhl@google.com> > Signed-off-by: Alice Ryhl <aliceryhl@google.com> > --- > [...]
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
| |