pub struct Id(/* private fields */);Expand description
Per-collection document identifier.
Wraps a NonZeroU64 so the on-disk value 0 is unambiguously
“no id”. Allocated by the catalog (M5 issue #38) via
Catalog::next_id — see that method for the full transactional
contract.
Id implements serde::Serialize + Deserialize + MaxSize so it
can appear in user Document types directly, including inside a
Vec<Id> or a nested struct. The serde encoding is the inner
NonZeroU64 — postcard varint-encodes it, and the deserializer
rejects the on-the-wire value 0 because NonZeroU64’s serde
impl already does the validation.
Implementations§
Source§impl Id
impl Id
Sourcepub const fn try_new(raw: u64) -> Option<Self>
pub const fn try_new(raw: u64) -> Option<Self>
Construct an Id from a raw u64. Returns None if raw
is 0 (per the sentinel-zero contract).
Sourcepub const fn from_nonzero(nz: NonZeroU64) -> Self
pub const fn from_nonzero(nz: NonZeroU64) -> Self
Total-function constructor: builds an Id from a
NonZeroU64 that the caller already proved is non-zero.
Use try_new at runtime boundaries.
Sourcepub const fn as_nonzero(self) -> NonZeroU64
pub const fn as_nonzero(self) -> NonZeroU64
The underlying NonZeroU64.
Sourcepub const fn to_be_bytes(self) -> [u8; 8]
pub const fn to_be_bytes(self) -> [u8; 8]
Big-endian byte encoding used as a key in a collection’s
primary B-tree. The big-endian shape makes lexicographic
byte comparison agree with numeric < on the underlying
u64 — the documented convention from docs/format.md
§ Key and value encoding.
Sourcepub fn from_be_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_be_bytes(bytes: &[u8]) -> Option<Self>
Decode a big-endian Id from bytes. Returns None if the
byte slice is the wrong length or names the sentinel zero.