Skip to main content

Snid

Struct Snid 

Source
#[repr(transparent)]
pub struct Snid(pub [u8; 16]);

Tuple Fields§

§0: [u8; 16]

Implementations§

Source§

impl Snid

Source

pub fn new() -> Self

Generates a new SNID with ~3.7ns latency. This is the universal paradigm for fast ID generation.

Source

pub fn try_new() -> Result<Self, Error>

Attempts to generate a new SNID without panicking on OS RNG failure.

Source

pub fn new_fast() -> Self

Generates a new SNID with lock-free per-P state. Deprecated: Use new() instead.

Source

pub fn new_with(opts: Options) -> Self

Generates a configured ID using options. This is the universal paradigm for configured ID generation.

Source

pub fn uuidv7() -> Self

Generates a SNID with RFC 9562 UUIDv7-compatible bytes.

Source

pub fn new_spatial(_lat: f64, _lng: f64) -> Self

Generates a spatial ID from lat/lng coordinates. This is the universal paradigm for spatial ID generation.

Source

pub fn batch(count: usize) -> Vec<Self>

Generates a batch of IDs efficiently. This is the universal paradigm for batch generation.

Source

pub fn try_batch(count: usize) -> Result<Vec<Self>, Error>

Attempts to generate a batch of IDs without panicking on OS RNG failure.

Source

pub fn fill_slice(out: &mut [Self])

Fills an existing ID slice in place.

This is the lowest-allocation generation API for callers that own their buffers, such as network send paths, database ingest loops, and arenas.

Source

pub fn fill_bytes(out: &mut [u8]) -> usize

Fills a byte buffer with raw SNID bytes and returns the number of IDs written.

Only complete 16-byte slots are written; trailing bytes are ignored.

Source

pub fn append_binary_batch(count: usize, out: &mut Vec<u8>)

Appends count raw 16-byte SNIDs to an existing byte buffer.

Source

pub fn from_bytes(bytes: [u8; 16]) -> Self

Source

pub fn to_bytes(self) -> [u8; 16]

Source

pub fn write_uuid_string(&self, out: &mut [u8; 36])

Writes the standard hyphenated UUID text form into out.

Source

pub fn to_uuid_string(&self) -> String

Returns the standard hyphenated UUID text form.

Source

pub fn from_uuid_string(value: &str) -> Result<Self, Error>

Parses a standard hyphenated UUID string into a SNID.

Only UUIDv7 values are accepted.

Source

pub fn from_hex(hex_value: &str) -> Result<Self, Error>

Source

pub fn canonical_atom(atom: &str) -> Option<&'static str>

Source

pub fn to_wire(self, atom: &str) -> Result<String, Error>

Source

pub fn write_wire<'a>( self, atom: &str, out: &'a mut [u8; 28], ) -> Result<&'a str, Error>

Writes a wire-format ID (ATOM:payload) into a stack-provided buffer.

The output buffer must be at least 28 bytes for canonical three-byte atoms.

Source

pub fn append_wire(self, atom: &str, out: &mut Vec<u8>) -> Result<(), Error>

Appends wire-format bytes into an existing buffer without allocating.

Source

pub fn to_wire_default(self) -> String

Formats an ID using the default wire format with “MAT:” atom. This is the universal paradigm for serialization (default atom). Note: Use the Display trait instead via format!(“{}”, id)

Source

pub fn with_atom(self, atom: &str) -> String

Formats an ID with a custom atom. This is the universal paradigm for serialization (override atom).

Source

pub fn to_base32(self) -> String

Formats an ID using Crockford Base32 encoding. This is case-insensitive and excludes ambiguous characters (I, L, O).

Source

pub fn write_base32(self, out: &mut [u8; 27]) -> &str

Writes Crockford Base32 text into out and returns the written slice.

Source

pub fn append_base32(self, out: &mut Vec<u8>)

Source

pub fn new_safe() -> Self

Generates a public-safe ID with time-blurring and pure CSPRNG entropy. This is the “One ID” solution for database PK + public API use. Time-blurring: Truncates timestamp to nearest second (instead of millisecond) Pure CSPRNG: Fills 74 bits with cryptographic randomness (no monotonic counter) Performance: ~40-50ns (vs 5ns for new())

Source

pub fn try_new_safe() -> Result<Self, Error>

Attempts to generate a public-safe ID without panicking on OS RNG failure.

Source

pub fn parse_wire(value: &str) -> Result<(Self, String), Error>

Source

pub fn parse(value: &str) -> Result<Self, Error>

Parses a wire string and returns the ID. This is the universal paradigm for parsing wire strings.

Source

pub fn parse_uuid(value: &str) -> Result<Self, Error>

Parses a UUID string and returns the ID. This is the universal paradigm for parsing UUID strings.

Source

pub fn timestamp_millis(self) -> i64

Source

pub fn to_tensor_words(self) -> (i64, i64)

Source

pub fn sequence(self) -> u16

Source

pub fn machine_or_shard(self) -> u32

Source

pub fn time_bin(self, resolution_millis: i64) -> i64

Source

pub fn is_ghosted(self) -> bool

Source

pub fn with_ghost_bit(self, enabled: bool) -> Self

Source

pub fn from_hash_with_timestamp(unix_millis: u64, hash: &[u8]) -> Self

Source

pub fn h3_cell(self) -> Option<u64>

Source

pub fn from_spatial_parts(cell: u64, entropy: u64) -> Self

Source

pub fn h3_feature_vector(self) -> Vec<u64>

Source§

impl Snid

Source

pub fn to_llm_format(self, atom: &str) -> Result<LlmFormatV1, Error>

Source

pub fn to_llm_format_v2(self, atom: &str) -> Result<LlmFormatV2, Error>

Trait Implementations§

Source§

impl Clone for Snid

Source§

fn clone(&self) -> Snid

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Snid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Snid

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Snid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for Snid

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Snid

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Snid

Source§

fn cmp(&self, other: &Snid) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Snid

Source§

fn eq(&self, other: &Snid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Snid

Source§

fn partial_cmp(&self, other: &Snid) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Snid

Source§

impl Eq for Snid

Source§

impl StructuralPartialEq for Snid

Auto Trait Implementations§

§

impl Freeze for Snid

§

impl RefUnwindSafe for Snid

§

impl Send for Snid

§

impl Sync for Snid

§

impl Unpin for Snid

§

impl UnsafeUnpin for Snid

§

impl UnwindSafe for Snid

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.