pub struct SeqGrant { /* private fields */ }Expand description
A contiguous block of count dense ordinals for one key, starting at
start, issued under one leadership epoch. Covers [start, start + count).
The only constructor, try_new, validates that the block is
non-empty (count >= 1) and that its last ordinal start + count - 1 does
not overflow u64. A constructed value is therefore proof that
last neither underflows nor wraps — the invariant lives in the
type, not in whatever code happened to build it. Mirrors WindowGrant.
Implementations§
Source§impl SeqGrant
impl SeqGrant
Sourcepub fn try_new(
key: SeqKey,
start: u64,
count: u32,
epoch: Epoch,
) -> Result<Self, CoreError>
pub fn try_new( key: SeqKey, start: u64, count: u32, epoch: Epoch, ) -> Result<Self, CoreError>
Construct a grant, validating that last is infallible.
Rejects count == 0 (CoreError::SeqCountZero) — a block covers at
least one ordinal, and last’s start + count - 1 would underflow — and
a block whose last ordinal start + count - 1 exceeds u64::MAX
(CoreError::SeqBlockOverflow). In the server’s serving path neither
can occur (count is validated 1..=max_seq_count and the durable
fetch-add already rejected an overflowing advance), but SeqGrant is
public, so the constructor enforces the invariant for every caller.
pub fn key(&self) -> &SeqKey
pub fn start(&self) -> u64
pub fn count(&self) -> u32
pub fn epoch(&self) -> Epoch
Sourcepub fn last(&self) -> u64
pub fn last(&self) -> u64
The last ordinal in the block: start + count - 1. Infallible:
try_new validated count >= 1 (so count - 1 does not
underflow) and that start + (count - 1) fits in u64, so a constructed
SeqGrant witnesses this cannot panic. The start + (count - 1)
association matches that check exactly — computing (start + count) - 1
would overflow the intermediate at the last() == u64::MAX boundary even
though the result fits.