Skip to content

How to serialize an integer as hexadecimal or binary? #781

Answered by epage
pastelmind asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry, I missed that you were referring to how TOML renders the number.

serde does not natively pass through custom formatting. Our options

  • Have a special wrapper type, like we do with serde_spanned. These are a pain to work with
  • Make it a setting on the deserializer that applies to all integers. This feels too niche to support.
  • Deserialzie to a toml_edit::Document and apply your own visitor.

I currently suggest the last one when people want to do custom formatting.

That leaves us with where you left off, a way to control what repr gets generated for numbers. The only way to do it today is for you to generate a valid TOML representation, parse it, and put it in the document. This is not…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@pastelmind
Comment options

@epage
Comment options

epage Sep 4, 2024
Maintainer

Answer selected by pastelmind
@pastelmind
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants