Skip to content

feat: add WrappingArithmetic trait, include in LinkReference bounds, re-export num-traits#147

Merged
konard merged 6 commits intomainfrom
issue-146-24c7ec323aac
Apr 14, 2026
Merged

feat: add WrappingArithmetic trait, include in LinkReference bounds, re-export num-traits#147
konard merged 6 commits intomainfrom
issue-146-24c7ec323aac

Conversation

@konard
Copy link
Copy Markdown
Member

@konard konard commented Apr 14, 2026

Summary

  • Added WrappingArithmetic composite trait bundling all 6 wrapping arithmetic traits from num-traits: WrappingAdd, WrappingSub, WrappingMul, WrappingNeg, WrappingShl, WrappingShr
  • Added WrappingArithmetic as a supertrait of LinkReference, so downstream crates can use T: LinkReference without needing explicit + WrappingAdd bounds
  • Re-exported all num-traits traits used in supertraits (PrimInt, AsPrimitive, ToPrimitive, FromPrimitive, Unsigned, Signed, and all 6 Wrapping* traits), so downstream crates can drop their direct num-traits dependency entirely

Motivation

After removing LinkType from platform-data (data-rs#16, data-rs#17), WrappingAdd is needed for wrapping unsigned arithmetic in Hybrid (internal/external link reference encoding). Currently data-rs must add num-traits as an explicit dependency and write T: LinkReference + WrappingAdd everywhere. With this change, T: LinkReference is sufficient.

The re-exports also address #141: downstream crates (data-rs, tree-rs, doublets-rs) can now import all needed num-traits directly from platform-num, eliminating version drift risk.

Design decisions

  • WrappingArithmetic name: The maintainer disliked WrappingAdd as a name to add directly. After researching num-traits, there is no existing composite wrapping trait. WrappingArithmetic bundles all 6 wrapping ops and follows the same composite pattern as Number (which bundles PrimInt + Default + Debug + AsPrimitive<usize> + ToPrimitive)
  • All 6 wrapping traits included: Not just WrappingAdd — includes WrappingSub, WrappingMul, WrappingNeg, WrappingShl, WrappingShr since all are implemented for all unsigned integer types
  • Compatible addition: All types that implement LinkReference (u8, u16, u32, u64, u128, usize) already implement all 6 wrapping traits
  • Re-exports: All num-traits traits that appear as supertraits in this crate are re-exported, following the pattern requested in Re-export num-traits traits (Unsigned, FromPrimitive) to allow dependents to remove direct num-traits dependency #141

Changes

File Change
rust/src/imp.rs New WrappingArithmetic trait + added as LinkReference supertrait
rust/src/lib.rs Export WrappingArithmetic, re-export all num-traits, updated docs table
rust/tests/traits.rs 16 new tests for wrapping arithmetic
changelog.d/ Changelog entry (bump: minor)
docs/case-studies/issue-146/ Case study analysis with raw data
experiments/ Verification scripts

Test plan

  • cargo build compiles cleanly
  • cargo fmt --all -- --check — no formatting issues
  • cargo clippy --all-targets — zero warnings
  • cargo test — 112 unit tests + 7 doc tests pass (was 96 + 6)
  • Verified all 6 wrapping traits implemented for u8, u16, u32, u64, u128, usize
  • CI pipeline passes (all jobs green)

Closes #146
Also addresses #141

🤖 Generated with Claude Code

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: #146
@konard konard self-assigned this Apr 14, 2026
konard and others added 2 commits April 14, 2026 12:24
…unds

Add a composite WrappingArithmetic trait that bundles all six wrapping
arithmetic traits from num-traits (WrappingAdd, WrappingSub, WrappingMul,
WrappingNeg, WrappingShl, WrappingShr). Include it as a supertrait of
LinkReference so downstream crates can use wrapping arithmetic with just
T: LinkReference without needing explicit + WrappingAdd bounds.

Closes #146

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Compile raw data from related issues (data-rs#16, data-rs#17,
doublets-rs#47) and write analysis covering timeline, root causes,
solution rationale, and downstream impact.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] Add WrappingAdd to LinkReference trait bounds feat: add WrappingArithmetic trait, include in LinkReference bounds Apr 14, 2026
CI manages versions automatically via changelog fragments.
Fix import order to satisfy rustfmt (ops::wrapping before top-level).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review April 14, 2026 12:34
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $4.185934
  • Calculated by Anthropic: $4.215934
  • Difference: $0.030000 (+0.72%)

📊 Context and tokens usage:

Claude Opus 4.6:

  • Context window: 102.3K / 1M (10%) input tokens, 22.8K / 128K (18%) output tokens

Total: (93.8K + 5.8M cached) input tokens, 22.8K output tokens, $4.059736 cost

Claude Haiku 4.5:

Total: (78.3K + 108.8K cached) input tokens, 3.9K / 64K (6%) output tokens, $0.126198 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus
  • Main model: Claude Opus 4.6 (claude-opus-4-6)
  • Additional models:
    • Claude Haiku 4.5 (claude-haiku-4-5-20251001)

📎 Log file uploaded as Gist (2485KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

I think as in #141 we should reexport all related num traites we inherited from num traites library and that can be useful for the users of our library, so there is no problems with synchronization of num traites library, and all data-rs, tree-rs and doublets-rs will be able to just drop the import of num traits directly.

@konard konard marked this pull request as draft April 14, 2026 12:38
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-04-14T12:38:54.299Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

Downstream crates (data-rs, tree-rs, doublets-rs) can now import
PrimInt, AsPrimitive, ToPrimitive, FromPrimitive, Unsigned, Signed,
and all six Wrapping* traits directly from platform-num, eliminating
the need for a separate num-traits dependency and avoiding version
drift risk.

Addresses #141

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title feat: add WrappingArithmetic trait, include in LinkReference bounds feat: add WrappingArithmetic trait, include in LinkReference bounds, re-export num-traits Apr 14, 2026
@konard konard marked this pull request as ready for review April 14, 2026 12:41
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $1.583205

📊 Context and tokens usage:

  • Context window: 52.7K / 1M (5%) input tokens, 9.2K / 128K (7%) output tokens

Total: (42.4K + 2.2M cached) input tokens, 9.2K output tokens, $1.583205 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus
  • Model: Claude Opus 4.6 (claude-opus-4-6)

📎 Log file uploaded as Gist (1242KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add WrappingAdd to LinkReference trait bounds

1 participant