Skip to main content

Crate odoid

Crate odoid 

Source
Expand description

OdoID — Deterministic mixed-radix ID encoding.

Maps a non-negative integer to a 6, 7, or 8-character alphanumeric string with a serial-number aesthetic. All ambiguous characters (I, L, O) are excluded from all positions to prevent transcription errors.

§Quick start

use odoid::{encode, decode, OdoIDGenerator, GeneratorConfig};

assert_eq!(encode(0,            6).unwrap(), "0A0000");
assert_eq!(encode(1234567,      6).unwrap(), "0D7NM7");
assert_eq!(encode(1234567,      7).unwrap(), "0A15NM7");
assert_eq!(encode(236223201279, 8).unwrap(), "ZZ9ZZZZZ");

assert_eq!(decode("0D7NM7").unwrap(), 1234567);

let mut g = OdoIDGenerator::new(GeneratorConfig {
    namespace: "orders".into(),
    length: 7,
    ..Default::default()
}).unwrap();
let result = g.next().unwrap();
assert_eq!(result.length, 7);

Structs§

GeneratorConfig
Configuration for OdoIDGenerator.
InvalidCharacterError
Returned when a character absent from the positional charset is encountered during decoding.
OdoIDGenerator
A distributed monotonic generator that produces OdoID strings driven by a namespace-scoped, time-seeded pseudo-random integer.
OdoIDResult
Value returned by OdoIDGenerator::next.
OverflowError
Returned when n >= MAX[length] for the chosen OdoID length.
UnsupportedLengthError
Returned when a length other than 6, 7, or 8 is requested.

Enums§

OdoError
Unified error type returned by encode and decode.

Constants§

ALL
Full hybrid set — NUM concatenated with ALPHA — radix 32.
ALPHA
Alpha characters (ambiguous chars I, L, O excluded) — radix 22.
MAX
Maximum exclusive value for each supported length. Formula: 32 × 22 × 10 × 32^(L-3) = 220 × 32^(L-2)
NUM
Numeric characters — radix 10.

Functions§

decode
Decodes an OdoID string back to its originating integer.
encode
Encodes a non-negative integer n into an OdoID string of the given length.