AtomicId

Struct AtomicId 

Source
pub struct AtomicId<const BITS: usize>;
Expand description

The main entry point for generating atomic IDs of a specific bit width.

Use the const generic BITS parameter to select the desired ID size. For 24 and 32-bit IDs, the short feature must be enabled.

§Examples

use atomic_id::{AtomicId, x64, x128};

// Generate a 64-bit ID
let id64 = AtomicId::<x64>::new();

// Generate a 128-bit ID
let id128 = AtomicId::<x128>::new();

Implementations§

Source§

impl AtomicId<64>

Source

pub fn new() -> String

Generate a new 64-bit ID, encoded as a 13-character base36 string.

§Example
use atomic_id::{AtomicId, x64};
let id = AtomicId::<x64>::new();
assert_eq!(id.len(), 13);
Source

pub fn base58() -> String

Generate a new 64-bit ID, encoded as an 11-character base58 string.

§Example
use atomic_id::{AtomicId, x64};
let id = AtomicId::<x64>::base58();
assert_eq!(id.len(), 11);
Source

pub fn base91() -> String

Generate a new 64-bit ID, encoded as a 10-character base91 string.

§Example
use atomic_id::{AtomicId, x64};
let id = AtomicId::<x64>::base91();
assert_eq!(id.len(), 10);
Source

pub fn base36() -> String

Generate a new 64-bit ID, encoded as a 13-character base36 string.

§Example
use atomic_id::{AtomicId, x64};
let id = AtomicId::<x64>::base36();
assert_eq!(id.len(), 13);
Source

pub fn hex() -> String

Generate a new 64-bit ID, encoded as a 16-character hexadecimal string.

§Example
use atomic_id::{AtomicId, x64};
let id = AtomicId::<x64>::hex();
assert_eq!(id.len(), 16);
Source

pub fn batch(n: usize) -> Vec<String>

Generate a batch of 64-bit IDs, encoded as base36 strings.

§Example
use atomic_id::{AtomicId, x64};
let ids = AtomicId::<x64>::batch(3);
assert_eq!(ids.len(), 3);
Source

pub fn base58_batch(n: usize) -> Vec<String>

Generate a batch of 64-bit IDs as base58 strings.

Source

pub fn base91_batch(n: usize) -> Vec<String>

Generate a batch of 64-bit IDs as base91 strings.

Source

pub fn base36_batch(n: usize) -> Vec<String>

Generate a batch of 64-bit IDs as base36 strings.

Source

pub fn hex_batch(n: usize) -> Vec<String>

Generate a batch of 64-bit IDs as hexadecimal strings.

Source

pub fn sequential() -> String

Generate a sequential 64-bit ID as a base36 string.

This method uses a simple atomic counter, making the IDs sequential but not time-sortable. It is useful for scenarios where strict ordering is more important than distributed uniqueness.

§Example
use atomic_id::{AtomicId, x64};
let id1 = AtomicId::<x64>::sequential();
let id2 = AtomicId::<x64>::sequential();
// id2 will be lexicographically greater than id1
assert!(id2 > id1);
Source

pub fn sequential_base58() -> String

Generate a sequential 64-bit ID as a base58 string.

Source

pub fn sequential_base91() -> String

Generate a sequential 64-bit ID as a base91 string.

Source

pub fn sequential_base36() -> String

Generate a sequential 64-bit ID as a base36 string.

Source

pub fn sequential_hex() -> String

Generate a sequential 64-bit ID as a hexadecimal string.

Source

pub fn sequential_batch(n: usize) -> Vec<String>

Generate a batch of sequential 64-bit IDs as base36 strings.

Source

pub fn sequential_base58_batch(n: usize) -> Vec<String>

Generate a batch of sequential 64-bit IDs as base58 strings.

Source

pub fn sequential_base91_batch(n: usize) -> Vec<String>

Generate a batch of sequential 64-bit IDs as base91 strings.

Source

pub fn sequential_base36_batch(n: usize) -> Vec<String>

Generate a batch of sequential 64-bit IDs as base36 strings.

Source

pub fn sequential_hex_batch(n: usize) -> Vec<String>

Generate a batch of sequential 64-bit IDs as hexadecimal strings.

Source§

impl AtomicId<128>

Source

pub fn new() -> String

Generate a new 128-bit ID, encoded as a 25-character base36 string.

§Example
use atomic_id::{AtomicId, x128};
let id = AtomicId::<x128>::new();
assert_eq!(id.len(), 25);
Source

pub fn base58() -> String

Generate a new 128-bit ID, encoded as a 22-character base58 string.

§Example
use atomic_id::{AtomicId, x128};
let id = AtomicId::<x128>::base58();
assert_eq!(id.len(), 22);
Source

pub fn base91() -> String

Generate a new 128-bit ID, encoded as a 20-character base91 string.

§Example
use atomic_id::{AtomicId, x128};
let id = AtomicId::<x128>::base91();
assert_eq!(id.len(), 20);
Source

pub fn base36() -> String

Generate a new 128-bit ID, encoded as a 25-character base36 string.

§Example
use atomic_id::{AtomicId, x128};
let id = AtomicId::<x128>::base36();
assert_eq!(id.len(), 25);
Source

pub fn hex() -> String

Generate a new 128-bit ID, encoded as a 32-character hexadecimal string.

§Example
use atomic_id::{AtomicId, x128};
let id = AtomicId::<x128>::hex();
assert_eq!(id.len(), 32);
Source

pub fn batch(n: usize) -> Vec<String>

Generate a batch of 128-bit IDs, encoded as base36 strings.

§Example
use atomic_id::{AtomicId, x128};
let ids = AtomicId::<x128>::batch(3);
assert_eq!(ids.len(), 3);
Source

pub fn base58_batch(n: usize) -> Vec<String>

Generate a batch of 128-bit IDs as base58 strings.

Source

pub fn base91_batch(n: usize) -> Vec<String>

Generate a batch of 128-bit IDs as base91 strings.

Source

pub fn base36_batch(n: usize) -> Vec<String>

Generate a batch of 128-bit IDs as base36 strings.

Source

pub fn hex_batch(n: usize) -> Vec<String>

Generate a batch of 128-bit IDs as hexadecimal strings.

Source§

impl AtomicId<256>

Source

pub fn new() -> String

Generate a new 256-bit ID, encoded as a 52-character base36 string.

The raw 256-bit ID is composed of four 64-bit parts, each of which is encoded into a 13-character base36 string and then joined.

§Example
use atomic_id::{AtomicId, x256};
let id = AtomicId::<x256>::new();
assert_eq!(id.len(), 52);
Source

pub fn base58() -> String

Generate a new 256-bit ID, encoded as a 44-character base58 string.

§Example
use atomic_id::{AtomicId, x256};
let id = AtomicId::<x256>::base58();
assert_eq!(id.len(), 44);
Source

pub fn base91() -> String

Generate a new 256-bit ID, encoded as a 40-character base91 string.

§Example
use atomic_id::{AtomicId, x256};
let id = AtomicId::<x256>::base91();
assert_eq!(id.len(), 40);
Source

pub fn base36() -> String

Generate a new 256-bit ID, encoded as a 52-character base36 string.

§Example
use atomic_id::{AtomicId, x256};
let id = AtomicId::<x256>::base36();
assert_eq!(id.len(), 52);
Source

pub fn hex() -> String

Generate a new 256-bit ID, encoded as a 64-character hexadecimal string.

§Example
use atomic_id::{AtomicId, x256};
let id = AtomicId::<x256>::hex();
assert_eq!(id.len(), 64);
Source

pub fn batch(n: usize) -> Vec<String>

Generate a batch of 256-bit IDs, encoded as base36 strings.

§Example
use atomic_id::{AtomicId, x256};
let ids = AtomicId::<x256>::batch(3);
assert_eq!(ids.len(), 3);
Source

pub fn base58_batch(n: usize) -> Vec<String>

Generate a batch of 256-bit IDs as base58 strings.

Source

pub fn base91_batch(n: usize) -> Vec<String>

Generate a batch of 256-bit IDs as base91 strings.

Source

pub fn base36_batch(n: usize) -> Vec<String>

Generate a batch of 256-bit IDs as base36 strings.

Source

pub fn hex_batch(n: usize) -> Vec<String>

Generate a batch of 256-bit IDs as hexadecimal strings.

Auto Trait Implementations§

§

impl<const BITS: usize> Freeze for AtomicId<BITS>

§

impl<const BITS: usize> RefUnwindSafe for AtomicId<BITS>

§

impl<const BITS: usize> Send for AtomicId<BITS>

§

impl<const BITS: usize> Sync for AtomicId<BITS>

§

impl<const BITS: usize> Unpin for AtomicId<BITS>

§

impl<const BITS: usize> UnwindSafe for AtomicId<BITS>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.