-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add output_extensions
option to PrettyConfig
#339
Conversation
output_extensions
option to PrettyConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit skeptical about this originally, but I think this is the best solution.
However, I think we should provide a safer API to make it less confusing and error prone. I was thinking something like this:
fn ron_options() {
ron::Options::build().implicit_some().build()
}
let ron = ron_options();
let foo: Foo = ron.from_file("foo.ron")?;
ron.to_file("foo.ron")?; // same options used for deserialization and serialization
ron.to_file_pretty("foo.ron", PrettyConfig::default())?;
We should also make sure to provide such a code snippet as documentation and to explain that one has to use the same options for serialization and deserialization. I think doing all this cleanly might involve some breaking API changes, not sure.
@@ -191,6 +193,16 @@ impl PrettyConfig { | |||
|
|||
self | |||
} | |||
|
|||
/// Configures whether the extensions are included in the output as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should describe the use-case here and what to look out for (enabling the same extensions when deserializing).
I really like the design you are proposing here. Do you think it would be best to first implement this new API and then after that the functionality to turn off the extension outputting? I might make sense to give a nicer usage example. |
Yes, I think that would be the best approach @MomoLangenstein 👍 |
Ok, I'll write that up then (maybe tomorrow) |
This PR will be superseded by #343 and closed once that is merged |
With #343 this has now become obsolete |
This PR adds an extra on-by-default configuration option to
PrettyConfig
. Whenoutput_extensions
is set tofalse
, the serialized RON will not include the#![enable(EXTENSION)]
attributes.This would also be related to #281, i.e. for use cases where RON is used e.g. for a configuration file that is both produced and consumed by the same program, extensions could be automatically enabled on deserialization and removed on serialization to remove the overhead.
While programmatically enabling extensions is doable already (just insert the attribute-enabling string before the RON), disabling them is much harder as you would have to parse and match on the attributes' format.
CHANGELOG.md