rust-cli/confy

How to use non Caps or non Camelcase in variants

adrianboston opened this issue · 2 comments

In my properties i have the following enum for a datetime. Which uses camelcase

pub enum DateTimeFormat {
    Rfc3339,
    Rfc2822,
    Epochms
}

My application toml file sets the property as such

datetime_format = 'Rfc3339'

If I use non cap

datetime_format = 'rfc3339'

it fails at

confy::load_path(inpath)

Is there an acceptable way of rectifying this in a deserializer

This is possible with a serde variant attribute rename_all

Changing your DateTimeFormat enum to:

#[derive(Default, Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum DateTimeFormat {
    #[default]
    Rfc3339,
    Rfc2822,
    Epochms,
}

will allow a config like the one below to deserialize correctly:

version = 0
datetime_format = 'rfc3339'

Thanks for the good pointer.
Instead, I went with lowercase and suppressed the warning using

#[allow(non_camel_case_types)]

This offers a better solution and I will revert back to CamelCase.