-
Notifications
You must be signed in to change notification settings - Fork 3
Decimal #11
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11 +/- ##
==========================================
+ Coverage 97.25% 97.40% +0.14%
==========================================
Files 59 59
Lines 1312 1308 -4
==========================================
- Hits 1276 1274 -2
+ Misses 36 34 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces the custom F64
wrapper with a new Decimal
type backed by rust_decimal::Decimal
, migrating all monetary and quantity models to use high-precision decimals via the dec!
macro.
- Introduces
models/decimal.rs
and addsdec
to the prelude for easy decimal literals - Updates
UnitPrice
,Quantity
,Cost
, exchange-rate logic, item builders, serialization, and tests to useDecimal
anddec!
- Renames the old
F64
wrapper inf64_eq.rs
toDecimal
, which now conflicts with the newDecimal
type
Reviewed Changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
crates/core/src/models/unit_price.rs | Switched UnitPrice from F64 to new Decimal , updated tests |
crates/core/src/models/quantity.rs | Switched Quantity to Decimal , added ONE constant |
crates/core/src/models/cost.rs | Switched Cost to Decimal |
crates/core/src/models/decimal.rs | New wrapper for rust_decimal::Decimal with serde + RON support |
crates/core/src/models/f64_eq.rs | Renamed F64 to Decimal but now collides with new Decimal |
crates/core/src/models/error.rs | Added InvalidDecimalConversion , updated parse error comments |
crates/core/src/logic/serde_to_typst.rs | Enhanced RON→Typst conversion for decimal strings |
Comments suppressed due to low confidence (1)
crates/core/src/models/f64_eq.rs:26
- The old
F64
wrapper was renamed toDecimal
, but there is already a newDecimal
type inmodels/decimal.rs
. Consider giving this wrapper a distinct name (e.g.,F64
orF64Bits
) or renaming the file to match.
pub struct Decimal(f64);
…l::Decimal which serializes into a number not a string
Remove custom F64 type, replaced with
Decimal
which is a wrapper aroundrust_decimal::Decimal
- changing the serde to serialise into a f64, not a string, for simplest possible bridging into Typst dictionary. In the future if anyone needs more precision than f64 we can remove the wrapper and just use Decimal as is, and let it serialize into a string, and write a more advanced bridge to Typst than going via JSON.