pub struct SnowflakeBuilder { /* private fields */ }Expand description
A builder for creating a Snowflake generator with custom configuration.
Implementations§
Source§impl SnowflakeBuilder
impl SnowflakeBuilder
Sourcepub fn with_worker_id(self, worker_id: u64) -> Self
pub fn with_worker_id(self, worker_id: u64) -> Self
Set the worker ID for the Snowflake generator.
Examples found in repository?
examples/custom_config.rs (line 10)
3fn main() -> Result<(), Box<dyn Error>> {
4 let worker_id = 1;
5 let worker_id_bits = 4;
6 let epoch: u64 = 1609459200000; // 2021-01-01 00:00:00.000 UTC
7
8 let mut snowflake = Snowflake::builder()
9 .with_worker_id_bits(worker_id_bits)
10 .with_worker_id(worker_id)
11 .with_epoch(epoch)
12 .build()?;
13
14 let sfid = snowflake.generate()?;
15 println!("Snowflake ID: {}", sfid);
16 Ok(())
17}Sourcepub fn with_worker_id_bits(self, worker_id_bits: u64) -> Self
pub fn with_worker_id_bits(self, worker_id_bits: u64) -> Self
Set the number of bits used for the worker ID.
Examples found in repository?
examples/custom_config.rs (line 9)
3fn main() -> Result<(), Box<dyn Error>> {
4 let worker_id = 1;
5 let worker_id_bits = 4;
6 let epoch: u64 = 1609459200000; // 2021-01-01 00:00:00.000 UTC
7
8 let mut snowflake = Snowflake::builder()
9 .with_worker_id_bits(worker_id_bits)
10 .with_worker_id(worker_id)
11 .with_epoch(epoch)
12 .build()?;
13
14 let sfid = snowflake.generate()?;
15 println!("Snowflake ID: {}", sfid);
16 Ok(())
17}Sourcepub fn with_timeout_millis(self, timeout_millis: u128) -> Self
pub fn with_timeout_millis(self, timeout_millis: u128) -> Self
Set the timeout duration for waiting for the next time period.
Sourcepub fn with_epoch(self, epoch: u64) -> Self
pub fn with_epoch(self, epoch: u64) -> Self
Set the epoch time.
Examples found in repository?
examples/custom_config.rs (line 11)
3fn main() -> Result<(), Box<dyn Error>> {
4 let worker_id = 1;
5 let worker_id_bits = 4;
6 let epoch: u64 = 1609459200000; // 2021-01-01 00:00:00.000 UTC
7
8 let mut snowflake = Snowflake::builder()
9 .with_worker_id_bits(worker_id_bits)
10 .with_worker_id(worker_id)
11 .with_epoch(epoch)
12 .build()?;
13
14 let sfid = snowflake.generate()?;
15 println!("Snowflake ID: {}", sfid);
16 Ok(())
17}Sourcepub fn build(self) -> Result<Snowflake, SnowflakeError>
pub fn build(self) -> Result<Snowflake, SnowflakeError>
Build the Snowflake generator with the specified configuration.
Examples found in repository?
examples/custom_config.rs (line 12)
3fn main() -> Result<(), Box<dyn Error>> {
4 let worker_id = 1;
5 let worker_id_bits = 4;
6 let epoch: u64 = 1609459200000; // 2021-01-01 00:00:00.000 UTC
7
8 let mut snowflake = Snowflake::builder()
9 .with_worker_id_bits(worker_id_bits)
10 .with_worker_id(worker_id)
11 .with_epoch(epoch)
12 .build()?;
13
14 let sfid = snowflake.generate()?;
15 println!("Snowflake ID: {}", sfid);
16 Ok(())
17}Auto Trait Implementations§
impl Freeze for SnowflakeBuilder
impl RefUnwindSafe for SnowflakeBuilder
impl Send for SnowflakeBuilder
impl Sync for SnowflakeBuilder
impl Unpin for SnowflakeBuilder
impl UnwindSafe for SnowflakeBuilder
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