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: u64Implementations§
Source§impl OdoIDGenerator
impl OdoIDGenerator
Sourcepub fn new(config: GeneratorConfig) -> Result<Self, UnsupportedLengthError>
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.
Sourcepub fn next_n(&mut self) -> u64
pub fn next_n(&mut self) -> u64
Returns the next raw integer n in [0, capacity).
Exposed for testing and low-level use.
Sourcepub fn next(&mut self) -> Result<OdoIDResult, OdoError>
pub fn next(&mut self) -> Result<OdoIDResult, OdoError>
Generates and returns the next OdoID.
Auto Trait Implementations§
impl Freeze for OdoIDGenerator
impl RefUnwindSafe for OdoIDGenerator
impl Send for OdoIDGenerator
impl Sync for OdoIDGenerator
impl Unpin for OdoIDGenerator
impl UnsafeUnpin for OdoIDGenerator
impl UnwindSafe for OdoIDGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more