macro_rules! size_of_field {
($type_name:ty, $($field:ident).+) => { ... };
}Expand description
Get the size of a field in a struct.
This is a compile-time equivalent of std::mem::size_of_val(&value.field).
Usage:
struct MyStruct {
field1: u8,
nested: Nested,
}
struct Nested {
field2: u32,
}
const FIELD1_SIZE: usize = size_of_field!(MyStruct, field1);
const FIELD2_SIZE: usize = size_of_field!(MyStruct, nested.field2);