pub struct Generator<F>where
F: FromIdGenerator,{ /* private fields */ }Expand description
simple snowflake generator
generates a given snowflake with the provided epoch and id value. epoch is
a specified date that can be in the future of
UNIX_EPOCH but not in the future of
now. the sequence value will always start at 1 when created.
if you want to wait for the next available id without calling the function
again check out blocking_next_id_mut
or other waiting methods depending on how you want to wait for the next
available id.
type MyFlake = snowcloud::i64::SingleIdFlake<43, 8, 12>;
type MyCloud = snowcloud::Generator<MyFlake>;
const START_TIME: u64 = 1679587200000;
let mut cloud = MyCloud::new(START_TIME, 1)
.expect("failed to create MyCloud");
println!("epoch: {:?}", cloud.epoch());
println!("ids: {}", cloud.ids());
println!("{:?}", cloud.next_id());Implementations§
Source§impl<F> Generator<F>where
F: FromIdGenerator + Sized,
impl<F> Generator<F>where
F: FromIdGenerator + Sized,
Sourcepub fn new<I>(epoch: u64, ids: I) -> Result<Self, Error>
pub fn new<I>(epoch: u64, ids: I) -> Result<Self, Error>
returns a new Generator
will return an error if the primary id is invalid, the timestamp is invalid, it failes to retrieve the current timestamp, or if the epoch is ahead of the current timestamp
Sourcepub fn epoch(&self) -> &SystemTime
pub fn epoch(&self) -> &SystemTime
returns epoch
Trait Implementations§
Source§impl<F> IdGeneratorMut for Generator<F>where
F: FromIdGenerator,
impl<F> IdGeneratorMut for Generator<F>where
F: FromIdGenerator,
Source§type Output = Result<<Generator<F> as IdGeneratorMut>::Id, <Generator<F> as IdGeneratorMut>::Error>
type Output = Result<<Generator<F> as IdGeneratorMut>::Id, <Generator<F> as IdGeneratorMut>::Error>
Auto Trait Implementations§
impl<F> Freeze for Generator<F>
impl<F> RefUnwindSafe for Generator<F>
impl<F> Send for Generator<F>
impl<F> Sync for Generator<F>
impl<F> Unpin for Generator<F>
impl<F> UnwindSafe for Generator<F>
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