instant-labs / instant-xml

11 stars 3 forks source link

`rename_all` container attribute #25

Closed rsdy closed 1 year ago

rsdy commented 1 year ago

Enable a container attribute rename_all that uses the renamer rules from serde. The following syntax is permitted to rename attributes of a struct or variants of an enum. These changes will not rename the XML tag generated from the struct name itself.

#[xml(scalar, rename_all = "UPPERCASE")]
pub enum TestEnum {
    Foo = 1,
    Bar,
    Baz
}

#[xml(rename_all = "UPPERCASE")]
pub struct TestStruct {
    field_1: String,
    field_2: u8,
}

The rename_all attribute may take on the following values:

This PR resolves #17 .

djc commented 1 year ago

17 requested the use of heck, why did you decide to not do that?

Also note that serde's rename_all requires that values are string literals, not paths.

rsdy commented 1 year ago

Since serde's usecase is equivalent to this, the boilerplate provided by the case.rs file allows us to straightforwardly plug in heck to do the conversion if need be. I don't see the reason to use the library at this stage, though, since this is already a comprehensive and well-tested suite.

As for the string literals instead of paths, that's an easy change to make.