Struct snowflake::SnowflakeIdBucket
source · [−]pub struct SnowflakeIdBucket { /* private fields */ }
Expand description
The SnowflakeIdBucket
type is snowflake-id-bucket it easy to get id also have a id buffer.
Implementations
sourceimpl SnowflakeIdBucket
impl SnowflakeIdBucket
sourcepub fn new(machine_id: i32, node_id: i32) -> Self
pub fn new(machine_id: i32, node_id: i32) -> Self
Constructs a new SnowflakeIdBucket
using the UNIX epoch.
Please make sure that machine_id and node_id is small than 32(2^5);
Examples
use snowflake::SnowflakeIdBucket;
let id_generator_bucket = SnowflakeIdBucket::new(1, 1);
sourcepub fn with_epoch(machine_id: i32, node_id: i32, epoch: SystemTime) -> Self
pub fn with_epoch(machine_id: i32, node_id: i32, epoch: SystemTime) -> Self
Constructs a new SnowflakeIdBucket
using the specified epoch.
Please make sure that machine_id and node_id is small than 32(2^5);
Examples
use std::time::{Duration, UNIX_EPOCH};
use snowflake::SnowflakeIdBucket;
// 1 January 2015 00:00:00
let discord_epoch = UNIX_EPOCH + Duration::from_millis(1420070400000);
let id_generator_bucket = SnowflakeIdBucket::with_epoch(1, 1, discord_epoch);
Trait Implementations
sourceimpl Clone for SnowflakeIdBucket
impl Clone for SnowflakeIdBucket
sourcefn clone(&self) -> SnowflakeIdBucket
fn clone(&self) -> SnowflakeIdBucket
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl RefUnwindSafe for SnowflakeIdBucket
impl Send for SnowflakeIdBucket
impl Sync for SnowflakeIdBucket
impl Unpin for SnowflakeIdBucket
impl UnwindSafe for SnowflakeIdBucket
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more