serde.rs hand-writes what derive already does #34

Closed
opened 2026-08-16 00:35:28 +00:00 by rosa · 0 comments
Owner

What to build

serde.rs hand-writes MoneyVisitor, MoneyField, MoneyFieldVisitor,
ExchangeRateVisitor, ExchangeRateField, and ExchangeRateFieldVisitor —
around 154 lines. What they implement is what #[derive(Deserialize)] does by
default: every named field required, unrecognized fields skipped, a repeated
field rejected.

Turn on serde's derive feature under the crate's existing optional serde
feature, and read each type through a private shadow struct that derives
Deserialize. ExchangeRate keeps its check that the rate is above zero.
Figure stays as it is: it holds the decimal shapes under this crate's control
rather than rust_decimal's, which is a decision worth keeping.

A crate that does not turn on the serde feature gains no new dependency.

The wire format does not change. The existing round-trip tests are the proof.

Acceptance criteria

  • The six visitor and field types are gone
  • Money and ExchangeRate read through derived shadow structs
  • A rate of zero or less is still rejected, with the same message
  • Unrecognized fields are still skipped and repeated fields still rejected
  • derive is enabled only under the optional serde feature
  • The existing serde round-trip and error tests pass unchanged
  • mise run ci passes

Blocked by

None — can start immediately.

## What to build `serde.rs` hand-writes `MoneyVisitor`, `MoneyField`, `MoneyFieldVisitor`, `ExchangeRateVisitor`, `ExchangeRateField`, and `ExchangeRateFieldVisitor` — around 154 lines. What they implement is what `#[derive(Deserialize)]` does by default: every named field required, unrecognized fields skipped, a repeated field rejected. Turn on serde's `derive` feature under the crate's existing optional `serde` feature, and read each type through a private shadow struct that derives `Deserialize`. `ExchangeRate` keeps its check that the rate is above zero. `Figure` stays as it is: it holds the decimal shapes under this crate's control rather than rust_decimal's, which is a decision worth keeping. A crate that does not turn on the `serde` feature gains no new dependency. The wire format does not change. The existing round-trip tests are the proof. ## Acceptance criteria - [ ] The six visitor and field types are gone - [ ] `Money` and `ExchangeRate` read through derived shadow structs - [ ] A rate of zero or less is still rejected, with the same message - [ ] Unrecognized fields are still skipped and repeated fields still rejected - [ ] `derive` is enabled only under the optional `serde` feature - [ ] The existing serde round-trip and error tests pass unchanged - [ ] `mise run ci` passes ## Blocked by None — can start immediately.
rosa closed this issue 2026-08-21 20:59:20 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rosa/lucre#34
No description provided.