pub struct SeqId(/* private fields */);Expand description
Sequence ID for MVCC versioning
Internally uses Snowflake ID format (64 bits):
- 41 bits: timestamp in milliseconds since custom epoch
- 10 bits: machine/worker ID
- 12 bits: sequence number
MVCC Architecture: Used as _seq column for version tracking
Storage key format: {user_id}:{_seq} or just {_seq} for shared tables
Implementations§
Source§impl SeqId
impl SeqId
Sourcepub const EPOCH: u64 = 1704067200000
pub const EPOCH: u64 = 1704067200000
Custom epoch: 2024-01-01 00:00:00 UTC (same as SnowflakeGenerator)
Sourcepub fn timestamp_millis(&self) -> u64
pub fn timestamp_millis(&self) -> u64
Extract timestamp in milliseconds since Unix epoch
This is useful for debugging, logging, and time-based queries.
Sourcepub fn timestamp_seconds(&self) -> u64
pub fn timestamp_seconds(&self) -> u64
Extract timestamp in whole seconds since Unix epoch
Sourcepub fn age_seconds(&self, now_millis: u64) -> u64
pub fn age_seconds(&self, now_millis: u64) -> u64
Compute how many whole seconds old this SeqId is relative to now_millis
Sourcepub fn timestamp(&self) -> SystemTime
pub fn timestamp(&self) -> SystemTime
Extract timestamp as SystemTime
Sourcepub fn to_bytes(&self) -> [u8; 8]
pub fn to_bytes(&self) -> [u8; 8]
Convert to bytes (big-endian for consistent ordering in RocksDB)
Sourcepub fn max_id_for_timestamp(timestamp_millis: u64) -> Result<SeqId, String>
pub fn max_id_for_timestamp(timestamp_millis: u64) -> Result<SeqId, String>
Return the maximum possible SeqId for the provided timestamp.
This packs the timestamp together with the largest worker/sequence values
so the returned SeqId encompasses every Snowflake generated at or before
timestamp_millis.
Trait Implementations§
impl Copy for SeqId
Source§impl<'de> Deserialize<'de> for SeqId
impl<'de> Deserialize<'de> for SeqId
Source§fn deserialize<D>(
deserializer: D,
) -> Result<SeqId, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<SeqId, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for SeqId
Source§impl Ord for SeqId
impl Ord for SeqId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for SeqId
impl PartialOrd for SeqId
Source§impl Serialize for SeqId
impl Serialize for SeqId
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl StorageKey for SeqId
impl StorageKey for SeqId
impl StructuralPartialEq for SeqId
Auto Trait Implementations§
impl Freeze for SeqId
impl RefUnwindSafe for SeqId
impl Send for SeqId
impl Sync for SeqId
impl Unpin for SeqId
impl UnsafeUnpin for SeqId
impl UnwindSafe for SeqId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.