Skip to main content

OdoIDGenerator

Struct OdoIDGenerator 

Source
pub struct OdoIDGenerator {
    pub namespace: String,
    pub length: usize,
    pub capacity: u64,
    /* private fields */
}
Expand description

A distributed monotonic generator that produces OdoID strings driven by a namespace-scoped, time-seeded pseudo-random integer.

The generator guarantees that rapid successive calls within the same millisecond tick produce distinct values via a monotonically incrementing sequence counter. Output is always in [0, capacity) so encode never returns OdoError::Overflow internally.

Fields§

§namespace: String§length: usize§capacity: u64

Implementations§

Source§

impl OdoIDGenerator

Source

pub fn new(config: GeneratorConfig) -> Result<Self, UnsupportedLengthError>

Creates a new OdoIDGenerator from config.

§Errors

Returns UnsupportedLengthError if config.length is not 6, 7, or 8.

Source

pub fn next_n(&mut self) -> u64

Returns the next raw integer n in [0, capacity). Exposed for testing and low-level use.

Source

pub fn next(&mut self) -> Result<OdoIDResult, OdoError>

Generates and returns the next OdoID.

Source

pub fn encode(&self, n: u64) -> Result<String, OdoError>

Encodes n using this generator’s configured length.

Source

pub fn decode(&self, id: &str) -> Result<u64, OdoError>

Decodes an OdoID string to its originating integer.

Auto Trait Implementations§

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.