Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/icrawl/rustflake
Thread-safe "twitter" snowflakes.
https://github.com/icrawl/rustflake
crate epoch rust snowflakes twitter
Last synced: about 4 hours ago
JSON representation
Thread-safe "twitter" snowflakes.
- Host: GitHub
- URL: https://github.com/icrawl/rustflake
- Owner: iCrawl
- License: mit
- Created: 2019-08-03T21:25:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-13T14:59:32.000Z (over 1 year ago)
- Last Synced: 2024-10-13T11:42:48.027Z (25 days ago)
- Topics: crate, epoch, rust, snowflakes, twitter
- Language: Rust
- Homepage: https://crates.io/crates/rustflake
- Size: 50.8 KB
- Stars: 36
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# rustflake
Thread-safe "twitter" snowflakes.
By default the original Twitter snowflake format defines:
- 41 bits are used to store a custom epoch with millisecond precision
- 10 bits are used to store worker and datacenter information
- 12 bits are used to store a sequence numberThis crate lets you customize your own epoch and worker/datacenter information.
## Usage
Add this to your `Cargo.toml`:```toml
[dependencies]
rustflake = "0.1.0"
```and this to your crate root:
```rust
use rustflake;
```## Example
```rust
use rustflake::Snowflake;fn main() {
let mut snowflake = Snowflake::default();
println!("{}", &snowflake.generate());
}
``````rust
use rustflake::Snowflake;fn main() {
// Discord Epoch
// Though those are not "real" discord Ids,
// because discord increases the sequence
// for *every* generated Id on that process
let mut snowflake = Snowflake::new(1420070400000, 1, 1);
println!("{}", &snowflake.generate());
}
``````rust
use rustflake::Snowflake;fn main() {
// Using a builder approach
let mut snowflake = Snowflake::default()
.epoch(1_564_790_400_000)
.worker_id(2)
.datacenter_id(3);
println!("{}", &snowflake.generate());
}
```