ron-rs / ron

Rusty Object Notation
https://docs.rs/ron
Apache License 2.0
3.22k stars 118 forks source link

Option to Expect Specific Struct Name Upon Deserialization #519

Closed sylv256 closed 6 months ago

sylv256 commented 8 months ago

I think it would be helpful to be able to enforce that a specific struct name is present when deserializing a struct. I mainly want to enforce this as part of style in my game's assets.

juntyr commented 8 months ago

Thank you for the suggestion @SylvKT! At the moment, RON allows a struct to either be unnamed or to have the same name that serde specifies. Do you want an extension to forbid the former, i.e. that structs must always mention their name?

sylv256 commented 8 months ago

Thank you for the suggestion @SylvKT! At the moment, RON allows a struct to either be unnamed or to have the same name that serde specifies. Do you want an extension to forbid the former, i.e. that structs must always mention their name?

Yes, I'm looking for a way to force the struct in RON to be both named and match the name provided by serde.

juntyr commented 8 months ago

@SylvKT Ok, thanks for the clarification! That shouldn’t be too difficult to add, my idea would be to add an extension, e.g. explicit_struct_names, and to check for it inside the struct parsing code. At the moment, we allow checking for the struct name to fail without modifying the parser state so that we can continue checking without a struct name. Now, if the struct name isn’t there, we would emit an error here.

At the moment, I’m unable to code it up myself for personal reasons but hopefully my explanation might be sufficient for you to submit a PR? I’d be happy to review it and to help you land it.