Skip to main content

Snowflake

Struct Snowflake 

Source
pub struct Snowflake<S: Storage> { /* private fields */ }
Expand description

Snowflake-based unique ID generator.

Implementations§

Source§

impl<S: Storage> Snowflake<S>

Source

pub async fn new( config: SnowflakeConfig, storage: Arc<S>, ) -> Result<Self, SnowflakeError>

Create a new Snowflake generator.

Source

pub async fn generate_u64(&self) -> Result<u64, SnowflakeError>

Generate a new unique ID as u64.

Source§

impl Snowflake<MemoryStorage>

Source

pub fn with_default() -> Self

Create a Snowflake generator with default configuration and memory storage.

Trait Implementations§

Source§

impl<S: Debug + Storage> Debug for Snowflake<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Storage + 'static> IdGenerator for Snowflake<S>

Source§

type Error = SnowflakeError

The error type for this generator.
Source§

fn generate( &self, ) -> Pin<Box<dyn Future<Output = Result<Id, Self::Error>> + Send + '_>>

Generate a single unique ID.
Source§

fn id_type(&self) -> IdType

Get the type of IDs this generator produces.
Source§

fn generate_batch( &self, count: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<Id>, Self::Error>> + Send + '_>>

Generate multiple unique IDs in batch.

Auto Trait Implementations§

§

impl<S> !Freeze for Snowflake<S>

§

impl<S> !RefUnwindSafe for Snowflake<S>

§

impl<S> Send for Snowflake<S>

§

impl<S> Sync for Snowflake<S>

§

impl<S> Unpin for Snowflake<S>

§

impl<S> UnsafeUnpin for Snowflake<S>

§

impl<S> !UnwindSafe for Snowflake<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.