pub enum IdGenStatus<T: Snowflake> {
Ready {
id: T,
},
Pending {
yield_until: T::Ty,
},
}Expand description
Represents the result of attempting to generate a new Snowflake ID.
This type models the outcome of SnowflakeGenerator::try_next_id():
IdGenStatus::Readyindicates a new ID was successfully generated.IdGenStatus::Pendingmeans the generator is throttled and cannot produce a new ID until the clock advances pastyield_until.
This allows non-blocking generation loops and clean backoff strategies.
§Example
use ferroid::{Snowflake, BasicSnowflakeGenerator, SnowflakeTwitterId, IdGenStatus};
struct FixedTime;
impl ferroid::TimeSource<u64> for FixedTime {
fn current_millis(&self) -> u64 {
1
}
}
let mut generator = BasicSnowflakeGenerator::<_, SnowflakeTwitterId>::from_components(0, 1, SnowflakeTwitterId::max_sequence(), FixedTime);
match generator.next_id() {
IdGenStatus::Ready { id } => println!("ID: {}", id.timestamp()),
IdGenStatus::Pending { yield_until } => println!("Back off until: {yield_until}"),
}Variants§
Ready
A unique ID was generated and is ready to use.
Fields
§
id: TThe generated Snowflake ID.
Pending
No ID could be generated because the sequence has been exhausted for the current tick.
You should wait until the clock reaches or exceeds yield_until before
attempting to generate a new ID again.
Trait Implementations§
Source§impl<T: Clone + Snowflake> Clone for IdGenStatus<T>
impl<T: Clone + Snowflake> Clone for IdGenStatus<T>
Source§fn clone(&self) -> IdGenStatus<T>
fn clone(&self) -> IdGenStatus<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<T: Copy + Snowflake> Copy for IdGenStatus<T>
impl<T: Eq + Snowflake> Eq for IdGenStatus<T>
impl<T: Snowflake> StructuralPartialEq for IdGenStatus<T>
Auto Trait Implementations§
impl<T> Freeze for IdGenStatus<T>
impl<T> RefUnwindSafe for IdGenStatus<T>
impl<T> Send for IdGenStatus<T>
impl<T> Sync for IdGenStatus<T>
impl<T> Unpin for IdGenStatus<T>
impl<T> UnwindSafe for IdGenStatus<T>
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
Mutably borrows from an owned value. Read more