Skip to content
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

Support serializing into inline tables #592

Closed
vlad-ivanov-name opened this issue Jul 30, 2023 · 1 comment
Closed

Support serializing into inline tables #592

vlad-ivanov-name opened this issue Jul 30, 2023 · 1 comment

Comments

@vlad-ivanov-name
Copy link

This issue is reopened from toml-rs/toml-rs#265 as it's still relevant

Given the following set of structures:

#[derive(Serialize)]
struct Inner {
    value: i32,
}

#[derive(Serialize)]
struct Outer {
   value: Inner,
}

#[derive(Serialize)]
struct SomeDocument {
   value: HashMap<String, Outer>,
}

It would be good to have a way to serialize Inner values as inline tables. Currently, to_string will make everything inline, and to_string_pretty will make everything a full table. It would be good to control this per-field, perhaps with a custom field attribute like what serde does.

@epage
Copy link
Member

epage commented Jul 31, 2023

serde does not provide a way for you to communicate intent. That just leaves us coming up with some heuristic which I'd like to avoid.

However, you can instead serialize into a toml_edit::Document and the the mod visit_mut API to format it however you wish. This is our generally recommended approach when people want custom formatting and so I'm planning to close this. If you have a reason for us to re-open, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants