Add FromByteSlice: fallible variable-length integer parse (0.1.2) - #13
Conversation
📝 WalkthroughWalkthroughThe crate version was bumped, and a new ChangesByte slice parsing API
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request bumps the crate version to 0.1.2-alpha.0 and adds a comprehensive proposal document detailing a byte-trait ecosystem for backend-agnostic numeric consumers. The review feedback suggests correcting inconsistent method names in the capability table, adding a native-endian parsing method (from_ne_slice) for completeness, and treating empty slice inputs as errors rather than defaulting to zero to prevent potential bugs.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Additive alpha cycle for the upcoming byte-trait work (a fallible variable-length FromByteSlice parse). Patch slot, not minor: this crate's change is purely additive; the only breaking change in the broader plan lives in the backend (fixed-bigint), not here.
854ecb9 to
c7c6138
Compare
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The design note uses
c0nst::c0nst!and similar pseudo-identifiers; consider adding a short note up front that this is illustrative syntax and mapping it explicitly to the real macro/paths to avoid confusion for readers trying to correlate with the actual code. - The
Open decisionssection is very helpful; you might want to turn these into explicit, numbered action items (with tentative resolutions or acceptance criteria) so it’s easier to track what must be settled before landing theFromByteSlice/ByteSliceErrorimplementation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The design note uses `c0nst::c0nst!` and similar pseudo-identifiers; consider adding a short note up front that this is illustrative syntax and mapping it explicitly to the real macro/paths to avoid confusion for readers trying to correlate with the actual code.
- The `Open decisions` section is very helpful; you might want to turn these into explicit, numbered action items (with tentative resolutions or acceptance criteria) so it’s easier to track what must be settled before landing the `FromByteSlice`/`ByteSliceError` implementation.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Capability (b) from the byte-trait ecosystem plan. FromBytes mirrors core's from_le_bytes — fixed width, infallible — and so can't parse a byte slice whose length the caller doesn't match to the target, nor reject over-length input. FromByteSlice fills that: from_be_slice / from_le_slice take a &[u8] of arbitrary length, zero-extend shorter input, and return a crate-owned ByteSliceError on over-width (never truncating) or empty input. Unsigned-only (zero-extension has no sign-extend analogue); crate-owned error mirrors AsciiParseError so it stays constructible on stable; const-callable on nightly (canary in const_nightly.rs). Additive — no existing item changes. Empty rejected rather than read as 0, so a truncated buffer can't pass as a valid zero (matches FromAscii). No from_ne_slice: native endianness is for fixed-width reinterpretation, not a variable-length parse.
The module header and ByteSliceError doc justified themselves by analogy to FromBytes / AsciiParseError. A reader doesn't care which trait it was modeled on, and the reference rots if the sibling changes. State the contract and the reason (fallible because an over-long slice has no lossless read; crate-owned because std's parse error is opaque) on their own terms.
A downstream `= "0.1.2"` requirement doesn't match a `0.1.2-alpha.0` pre-release without exact opt-in, which makes prototyping the byte-trait integration awkward. Carry the plain version and mark the alpha/prototype status with the git tag (v0.1.2-alpha.0) instead.
Opens the
0.1.2-alphaline and lands capability (b) from the byte-trait ecosystem plan: a fallible variable-length integer parse.Why
FromBytesmirrors core'sfrom_le_bytes— fixed width, infallible — so it can't parse a&[u8]whose length the caller doesn't match to the target width, and has no channel to reject over-length input.FromByteSlicefills that gap:Shorter-than-width input zero-extends; equal is exact; wider →
ByteSliceError { Overflow }(never truncates); empty →ByteSliceError { Empty }.Properties
ByteSliceError+ByteSliceErrorKind), mirroringAsciiParseError— constructible on stable, no std type.const_nightly.rs).Design feedback (from the earlier proposal doc)
Ok(0)— adopted. A truncated/missing buffer can't masquerade as a valid zero; matchesFromAscii.from_ne_slice— declined. Native endianness is for fixed-width reinterpretation (from_ne_byteson[u8; N]); a variable-length parse in "native" order is semantically dubious and invites misuse. Additive if ever wanted.rsa/new_reducecheck):len > width → Overflowregardless of whether surplus high bytes are zero.Not included
The backend-side changes (fixed-bigint
FromBytes::Bytes = [u8]flip,&BackendToBytes impl, const-eval inherent) and the ed25519/rsa rebindings land in their own repos. This PR is only the additive const-num-traits primitive.