0

After reading the chapter about the tuple structure and transparent layout. In case of struct definitions like this:

#[repr(C)]
pub(crate) struct InnerStruct {
    pub a: u32,
    pub b: u32,
    pub c: u32,
}

#[repr(transparent)]
pub OuterStruct(pub(crate) InnerStruct);

Normally we get access to inner struct's fields as following:

let outer = OuterStruct(...);
outer.0.a
outer.0.b

Is there any way to access these fields directly, like outer.a or outer.b without writing the .0?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
matthiascy
  • 75
  • 5
  • 1
    *reading the chapter* — **which** chapter? Link to it please. – Shepmaster Jul 02 '21 at 16:52
  • See also [Automatically implement traits of enclosed type for Rust newtypes (tuple structs with one field)](https://stackoverflow.com/q/24831573/155423); [Is it considered a bad practice to implement Deref for newtypes?](https://stackoverflow.com/q/45086595/155423) – Shepmaster Jul 02 '21 at 16:54

0 Answers0