feat(Rust): Add integer type inference option #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces integer type inference for Rust targets, providing better control over generated integer types (
i32
/i64
):Added
IntegerType
enum with variants:conservative
: Selectsi32
/i64
based on JSON sample rangesforce-i32
: Always usesi32
(caution: risk of overflow)force-i64
: Default behavior (current output)Added
integerType
configuration option for CLI and programmatic interfaces:quicktype --integer-type conservative # Smart selection (default) quicktype --integer-type force-i32
Related Issue
glideapps#2790
(Original feature request: glideapps#2790)
Motivation and Context
i64
even when values fit ini32
, causing:i32
force-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:
conservative
mode)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-i64
cargo check
Environment: