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

Add support for outputting integers as hexadecimal #812

Open
MatthewMorozov opened this issue Nov 15, 2024 · 1 comment
Open

Add support for outputting integers as hexadecimal #812

MatthewMorozov opened this issue Nov 15, 2024 · 1 comment
Labels
A-edit Area: TOML editing API A-output Area: Outputting TOML C-enhancement Category: Raise on the bar on expectations

Comments

@MatthewMorozov
Copy link

When using serde to serialize a data structure containing integers (u32, i16, etc) to TOML format, I would like the fields to be written in the generated TOML file in hexadecimal format. TOML format supports hexadecimal numbers, and this feature would make it easier to read fields such as 32-bit addresses. This may could be an option such as #[serde_with_format = "{:0X}"] above integer-type fields.

@epage epage added C-enhancement Category: Raise on the bar on expectations A-output Area: Outputting TOML A-edit Area: TOML editing API labels Nov 15, 2024
@epage
Copy link
Member

epage commented Nov 15, 2024

Some prior discussion at #781.

I don't see us supporting customization of formatting through serde. Serde doesn't natively support it. To support this, we'd need a newtype that serializes to a struct that toml recognizes as an integer with formatting. We'd support deserializing from either the struct or a number. This has some odd cases in serde, particularly that its not compatible with any other serialization format. Not just that the formatting gets ignored but that the number won't be sererialized correctly.

We can support this in toml_edit and people could deserialize to a DocumentMut and then apply a custom formatter. We'd just need to work out the API for customizing an integer's repr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edit Area: TOML editing API A-output Area: Outputting TOML C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

2 participants