Skip to content

feat(storable): implement Storable for unbounded 2-tuples [v0.6 backport]#435

Closed
lpahlavi wants to merge 1 commit intorelease/v0.6from
louis/unbounded-tuple-storable-v0.6
Closed

feat(storable): implement Storable for unbounded 2-tuples [v0.6 backport]#435
lpahlavi wants to merge 1 commit intorelease/v0.6from
louis/unbounded-tuple-storable-v0.6

Conversation

@lpahlavi
Copy link
Copy Markdown
Contributor

@lpahlavi lpahlavi commented Apr 21, 2026

Cherry-pick of #434 onto v0.6.9.

Summary

  • Replaces the two todo!() panics in the (A, B) Storable impl (to_bytes and from_bytes) with a working implementation for unbounded tuples.
  • The bounded 2-tuple wire format is unchanged — no backwards-compatibility break.
  • Adapted from the main cherry-pick: because v0.6 has no into_bytes method, the unbounded logic is inlined directly in to_bytes, matching the style of the v0.6 3-tuple implementation.

Wire format for unbounded (A, B)

If A is fixed-size:
  <a_bytes> <b_bytes>
Otherwise:
  <size_lengths (1B)> <size_a (1-4B)> <a_bytes> <b_bytes>

🤖 Generated with Claude Code

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Backports the main-branch work from #434 to v0.6.9, implementing support for (A, B) tuple serialization/deserialization when either element is unbounded, while keeping the existing bounded 2-tuple wire format unchanged for backwards compatibility.

Changes:

  • Implement unbounded (A, B) tuple Storable::to_bytes and Storable::from_bytes using the established size-lengths header approach (only when needed).
  • Add property-based and unit tests covering unbounded 2-tuples, mixed bounded/unbounded tuples, optional tuples, and BOUND/fixed-size expectations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/storable/tuples.rs Replaces todo!() paths with a concrete unbounded 2-tuple wire format implementation consistent with existing tuple encoding patterns.
src/storable/tests.rs Adds proptest coverage and bound assertions to validate unbounded and mixed bounded/unbounded 2-tuple behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Replaces the two `todo!()` panics in the `(A, B)` `Storable` impl
(`into_bytes_inner_2` and `from_bytes`) with a working implementation
for unbounded tuples. The bounded 2-tuple wire format is unchanged.

Wire format for unbounded `(A, B)`, documented in a comment inside the
impl block mirroring the 3-tuple style:

  If A is fixed-size:
    <a_bytes> <b_bytes>
  Otherwise:
    <size_lengths (1B)> <size_a (1-4B)> <a_bytes> <b_bytes>

`size_lengths` encodes (in 2 bits) the number of bytes used to store
`size_a`, matching the encoding already used by the 3-tuple path.
`B`'s length is always inferred from the remaining bytes.

Tests mirror the 3-tuple unbounded test coverage:
- `tuple_with_two_unbounded_elements_roundtrip`
- `tuple_with_two_elements_bounded_and_unbounded_roundtrip` (with byte count)
- `optional_tuple_with_two_unbounded_elements_roundtrip`
- `optional_tuple_with_two_elements_bounded_and_unbounded_roundtrip`
- `tuple_with_two_elements_test_bound`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lpahlavi lpahlavi force-pushed the louis/unbounded-tuple-storable-v0.6 branch from 5740352 to 109072f Compare April 21, 2026 12:59
@lpahlavi lpahlavi closed this Apr 21, 2026
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.

2 participants