Expand description
A pure Rust and fully tested KSUID implementation
This library is fully compatible with Segment’s KSUID implementation: https://github.com/segmentio/ksuid
§What is a ksuid?
A ksuid is a K sorted UID. In other words, a KSUID also stores a date component, so that ksuids can be approximately sorted based on the time they were created.
Read more here.
§Usage
Add the dependency:
[dependencies]
svix-ksuid = "^0.6.0"
use svix_ksuid::*;
let ksuid = Ksuid::new(None, None);
println!("{}", ksuid.to_string());
// 1srOrx2ZWZBpBUvZwXKQmoEYga2
§Higher timestamp accuracy mode
Ksuids have a 1 second accuracy which is not sufficient for all use-cases. That’s why this library exposes a higher accuracy mode which supports accuracy of up to 4ms.
It’s fully compatible with normal ksuids, in fact, it outputs valid ksuids. The difference is that it sacrifices one byte of the random payload in favor of this accuracy.
The code too is fully compatible:
use svix_ksuid::*;
let ksuid = KsuidMs::new(None, None);
And they both implement the same KsuidLike
trait.
§Opt-in features
serde
- adds the ability to serialize and deserializeKsuid
andKsuidMs
using serde.
Make sure to enable like this:
[dependencies]
svix-ksuid = { version = "^0.6.0", features = ["serde"] }
§License
ksuid source code is available under an MIT License.
All rights reserved to the Svix webhooks service.
Structs§
Constants§
Traits§
- Ksuid
Like - K-Sortable Unique ID Trait