-
Notifications
You must be signed in to change notification settings - Fork 64
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
[Feature]: Optionally accept integers where floats are expected #131
Comments
Maybe a dumb question, but can you cast with |
Yes, but that'd require putting a wrapper type that can be converted like that in every place I want to accept an
Yep fair, to be clear I'm asking for a runtime parameter, not a feature flag. I guess what that'd map to is a new Then the default behavior would be the current one (which makes the most sense in pure Rust scenarios) but more lenient behavior can be opted into on a per-call basis. |
Also just to be as clear as possible, this is all in the context of a serde |
@Gutawer does |
Is there an existing issue for this?
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 usesciborium
internally) and then trying to decode it intof32
on my Rust side givesSemantic(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
The text was updated successfully, but these errors were encountered: