I have some settings I wish to be able to configure over a CLI, however, the setting enum often has structs which have most of the configuration information.
pub struct NetworkSettings {
dhcp: bool,
}
pub struct UartSettings {
baud: u32
}
pub enum Setting {
/// Global network settings
Network(NetworkSettings),
/// Settings for a given uart, the first param is the uart number
Uart(usize, UartSettings),
}
As things currently stand, the derive can't handle this, and would require me to duplicate the fields in the enum.
I'm wondering:
- Is there a reason why structs were not supported (is there some technical reason)?
- Would some kind of
#[flatten] attribute to handle the above conversion automatically make sense?
pub enum Setting {
/// Global network settings
Network(#[flatten] NetworkSettings),
/// Settings for a given uart, the first param is the uart number
Uart(usize, #[flatten] UartSettings),
}
I'm happy to contribute, I just need a bit of direction as proc_macros are my weakest area of Rust.
I have some settings I wish to be able to configure over a CLI, however, the setting
enumoften has structs which have most of the configuration information.As things currently stand, the
derivecan't handle this, and would require me to duplicate the fields in the enum.I'm wondering:
#[flatten]attribute to handle the above conversion automatically make sense?I'm happy to contribute, I just need a bit of direction as proc_macros are my weakest area of Rust.