docs.rs failed to build grain-id-0.14.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
grain-id-0.16.0
grain-id
Compact, human-readable unique IDs — grain-sized, yet enough for a lifetime.
For a language agnostic specification of the grain-id format, see SPECS.md
Quick Start
use GrainId;
let id = random;
println!; // e.g. "123abcd"
Why grain-id?
Traditional identifier systems face challenges in distributed environments:
- Sequential numbers (like GitHub issue numbers) cause collisions in distributed systems
- UUIDs are too long and not human-friendly
- Short hashes (like Git commit hashes) lack standardization
grain-id bridges the gap between human readability and technical requirements.
Installation
Add this to your Cargo.toml:
[]
= "0.14.1"
# With optional features
= { = "0.14.1", = ["arbitrary", "serde", "rusqlite", "sea-orm", "prost", "redb", "schemars"] }
For no_std Environments
This crate support no_std.
For no_std environment, you'll need to disable default features.
[]
= { = "0.14.1", = false }
Features
- Human-friendly: Easy to read, type, and communicate
- Collision-resistant: Sufficient entropy for personal distributed systems
- Compact: Shorter than UUIDs while maintaining uniqueness
- Type-safe: Rust implementation with strong typing
- Multiple integrations: Support for serde, rusqlite, sea-orm, and protobuf
Optional Feature Flags
arbitrary:arbitrary::Arbitrarysupport for fuzzing tests.digest: Hash-basedGrainIdgeneration viadigest::Digesttrait.serde: Serialization/deserialization supportrusqlite: SQLite database integrationsea-orm: SeaORM ORM integrationprost: Protocol Buffers supportredb:redbintegrationschemars: JSON Schema support
Examples
use GrainId;
// Generate random grain-id
let grain_id = random;
// e.g. `123abcd`
println!;
// Parse from string
let valid_id: GrainId = "012atvw".parse?;
// When decoding from BASE32, ambiguous characters (1/l/I, 0/o, v/u) are treated as 1, 0 and v respectively, so they do not cause errors.
let also_valid_id: GrainId = "ol2atuw".parse?;
assert_eq!;
// Convert to/from integer
let num: u64 = valid_id.into;
let id_from_int: GrainId = num.try_into?;
assert_eq!;
// Lossy conversion from oversized int is allowed.
let id_from_overflowed_int = from_u64_lossy;
assert_eq!;
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.