Skip to content

Clean up configuration API #105

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

Closed
phrohdoh opened this issue May 20, 2018 · 10 comments
Closed

Clean up configuration API #105

phrohdoh opened this issue May 20, 2018 · 10 comments

Comments

@phrohdoh
Copy link

I'd like the ability to enable struct_names (via PrettyConfig) in

struct_names: false,
.

@torkleyy
Copy link
Contributor

Hey! You can use Serializer::new for now.

@torkleyy
Copy link
Contributor

I think this is part of a bigger issue, the configuration API could use some clean up.

@torkleyy torkleyy changed the title Unhardcode struct_names bool in to_string_pretty Clean up configuration API Oct 16, 2018
@torkleyy
Copy link
Contributor

torkleyy commented Jun 6, 2019

I've improved the config in #173, but I'm not quite sure about struct_names. The thing is, it can be set independently of a PrettyConfig, i.e. it can also be used for non-pretty serialization.

@torkleyy torkleyy closed this as completed Jun 6, 2019
@ghost
Copy link

ghost commented Dec 17, 2019

would there be any reason to not add this to PrettyConfig (with default value as false)?

I was able to work around this using Serializer::new as you described, but as a newbie in Rust it took me a while to work out how to do it (there's a few extra steps involved). Maybe at the very least it would be helpful to have this as example code somewhere in the examples or docs.

@kvark
Copy link
Collaborator

kvark commented Dec 17, 2019

@j-n-f the reason was outlined by a comment above yours:

The thing is, it can be set independently of a PrettyConfig, i.e. it can also be used for non-pretty serialization.

@ghost
Copy link

ghost commented Dec 18, 2019

Would a pull request to include this method of doing things in the documentation/examples be helpful?

@kvark
Copy link
Collaborator

kvark commented Dec 18, 2019

@j-n-f please clarify what "this method" you are referring to?

@ghost
Copy link

ghost commented Dec 18, 2019

@kvark I had to do something like the following (which is what I mean by "this method"):

// Create a serializer with `struct_names` set to `true`
let mut serializer = ron::ser::Serializer::new(Some(pretty_config), true);
application_struct_instance.serialize(&mut serializer).expect("couldn't serialize");
let serialized = serializer.into_output_string();

This is compared to the "easy" way that ron provides that would look more like:

let serialized = application_struct_instance.to_string_pretty(pretty_config);

I think an example named something like with_struct_names.rs would be helpful.

@kvark
Copy link
Collaborator

kvark commented Dec 18, 2019

@torkleyy I'm inclined to suggest that we just don't make this configurable for non-pretty path and skip the struct names. This would mean moving the flag into PrettyConfig.

@torkleyy
Copy link
Contributor

Yeah, let's do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants