Expand description
This crate allows for fixed length 64 bit integers to be represented as base64url encoded strings. This is useful for exchanging unique identifiers in a web based contexts; eg. sending an SQL primary key to a client with as few character as possible.
This crate is #![no_std] by default.
You can use the std cargo feature flag to enable support for the standard library
Quick Start
Add the following to your Cargo.toml file.
[dependencies]
base64id = { version = "0.1", features = ["std", "rand"] }Encoding
You can use the rand feature flag to generate a random ID like so.
use rand::random;
use base64id::Id64;
fn main() {
let id: Id64 = random();
println!("{id}"); // 3Zohppb9XMw
}Decoding
You can decode a string into an Id64 using it’s TryFrom impl.
use std::str::FromStr;
use base64id::{Error, Id64};
fn main() -> Result<(), Error> {
let id = Id64::from_str("AAAAAAAAAAE")?;
assert_eq!(id, Id64::from(1u64));
Ok(())
}Refer to the Error enum regarding decode errors.
Random Values for Development
From the command line you can quickly generate your own random Id64 values, along with their corosponding i64 and u64 integers.
cargo run --example random_sampleWarning! The output of this command is not guarentted to be stable, and may change at anytime.