ciborium
ciborium copied to clipboard
[Feature]: Optionally accept integers where floats are expected
Is there an existing issue for this?
- [X] I have searched the existing issues
Description
Apologies if there's already a way to do this outside of the library, I'm not massively familiar with the serde ecosystem yet.
I'm currently using this library as a "wire format" for a WASM plugin to the typst typesetting/programming language. Generally the experience has been really good but I'm running into a minor little thing which I'd like to know if there's a way around. Namely, the typst language always allows you to parse in an integer where a float is expected, but I don't see an easy way to replicate that with this library. Doing cbor.encode(1)
in typst (which uses ciborium
internally) and then trying to decode it into f32
on my Rust side gives Semantic(None, "invalid type: integer `1`, expected float")
, creating unexpected behavior given the context.
That behavior makes perfect sense for a Rust-encode, Rust-decode application, so I'm not asking for it to be changed. I'd just like if there was an optional flag for enabling this behavior for when it makes sense to - for example I'd also expect input encoded from Python to have the same expectation, since ints implicitly coerce to floats there too.
I'm happy to look at implementing this if it'd be accepted.
Acceptance Criteria
No response
Suggestions for a technical implementation
No response