feat(Rust): Add integer type inference option#2791
Conversation
1. Added IntegerType enum 2. Introduced integerType configuration option - Supports forced i32/i64 usage - Enables automatic selection based on numerical range
|
This PR has merge conflicts with master, and "allow edits from maintainers" is not enabled on the fork, so we can't update the branch for you. Could you merge master (or rebase) and resolve the conflicts? Enabling maintainer edits would also let us help with future conflicts. Thanks! |
|
Thanks for this feature, @jonashao — it's exactly what #2790 asked for, and we want it in the upcoming major release. Since this PR doesn't allow maintainer edits, we've carried it forward in #2964, with your commit as the base of that branch so your authorship is preserved. On top of it we fixed the conservative mode to require both bounds before choosing i32 (a one-sided If you'd prefer to update this PR yourself instead, we're happy to review — otherwise we'll proceed with #2964. Thanks again! |
Description
This PR introduces integer type inference for Rust targets, providing better control over generated integer types (
i32/i64):Added
IntegerTypeenum with variants:conservative: Selectsi32/i64based on JSON sample rangesforce-i32: Always usesi32(caution: risk of overflow)force-i64: Default behavior (current output)Added
integerTypeconfiguration option for CLI and programmatic interfaces:quicktype --integer-type conservative # Smart selection (default) quicktype --integer-type force-i32Related Issue
#2790
(Original feature request: #2790)
Motivation and Context
i64even when values fit ini32, causing:i32force-i32)force-i64)conservative)Previous Behaviour / Output
All integers unconditionally became
i64:New Behaviour / Output
With
--integer-type conservative:How Has This Been Tested?
Unit Tests:
conservativemode)force-i32/force-i64)Validation Tests:
# Tested with sample datasets: script/quicktype -s schema test/inputs/schema/integer-type.schema -o out.rs script/quicktype -s schema test/inputs/schema/integer-type.schema -o out.rs --integer-type force-i32 script/quicktype -s schema test/inputs/schema/integer-type.schema -o out.rs --integer-type force-i64cargo checkEnvironment: