UUIDLike

Struct UUIDLike 

Source
pub struct UUIDLike(/* private fields */);
Expand description

A wrapper for 128-bit values that may or may not be valid TNIDs.

This type provides a way to work with 128-bit UUID-like values without the strict validation that Tnid requires. Unlike Tnid, which only accepts values that conform to the TNID specification (correct UUIDv8 version/variant bits and valid name encoding), UUIDLike accepts any 128-bit value.

This makes UUIDLike useful for:

  • Inspecting potentially invalid TNIDs to understand why they don’t parse
  • Converting between different UUID representations (u128, hex strings) without validation
  • Working with UUIDs from external systems that may not be TNIDs
  • Debugging and troubleshooting TNID-related issues

§Examples

Basic usage:

use tnid::UUIDLike;

// Create from any 128-bit value
let uuid_like = UUIDLike::new(0x12345678_1234_1234_1234_123456789abc);

// Convert to different representations
let as_u128 = uuid_like.as_u128();
let as_string = uuid_like.to_uuid_string_cased(false);

Inspecting potentially invalid TNIDs:

use tnid::{UUIDLike, Tnid, TnidName, NameStr};

struct User;
impl TnidName for User {
    const ID_NAME: NameStr<'static> = NameStr::new_const("user");
}

// Parse a UUID string that might not be a valid TNID
let uuid_str = "cab1952a-f09d-86d9-928e-96ea03dc6af3";
let uuid_like = UUIDLike::parse_uuid_string(uuid_str).unwrap();

// Try to convert to TNID - this performs validation
match Tnid::<User>::from_u128(uuid_like.as_u128()) {
    Some(tnid) => println!("Valid TNID: {}", tnid),
    None => println!("Not a valid TNID (wrong version/variant/name)"),
}

Implementations§

Source§

impl UUIDLike

Source

pub fn as_u128(&self) -> u128

Returns the raw 128-bit value.

§Examples
use tnid::UUIDLike;

let uuid_like = UUIDLike::new(0x12345678_1234_1234_1234_123456789abc);
assert_eq!(uuid_like.as_u128(), 0x12345678_1234_1234_1234_123456789abc);
Source

pub fn new(id: u128) -> Self

Creates a new UUIDLike from a 128-bit value.

Accepts any u128 value without validation.

§Examples
use tnid::UUIDLike;

let uuid_like = UUIDLike::new(0x12345678_1234_1234_1234_123456789abc);
assert_eq!(uuid_like.as_u128(), 0x12345678_1234_1234_1234_123456789abc);
Source

pub fn to_uuid_string_cased(&self, uppercase: bool) -> String

Converts to UUID hex string format with specified case.

Produces the standard UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

§Parameters
  • uppercase: If true, uses uppercase hex digits (A-F). If false, uses lowercase (a-f).
§Examples
use tnid::UUIDLike;

let uuid_like = UUIDLike::new(0xCAB1952A_F09D_86D9_928E_96EA03DC6AF3);

let lowercase = uuid_like.to_uuid_string_cased(false);
assert_eq!(lowercase, "cab1952a-f09d-86d9-928e-96ea03dc6af3");

let uppercase = uuid_like.to_uuid_string_cased(true);
assert_eq!(uppercase, "CAB1952A-F09D-86D9-928E-96EA03DC6AF3");
Source

pub fn parse_uuid_string(uuid_string: &str) -> Option<Self>

Parses a UUID hex string into a UUIDLike.

Accepts the standard UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Accepts both uppercase and lowercase hex digits. Validates format but not TNID-specific requirements.

Returns None if the string is not a valid UUID hex string.

§Examples
use tnid::UUIDLike;

// Parse lowercase
let uuid = UUIDLike::parse_uuid_string("cab1952a-f09d-86d9-928e-96ea03dc6af3");
assert!(uuid.is_some());

// Parse uppercase
let uuid = UUIDLike::parse_uuid_string("CAB1952A-F09D-86D9-928E-96EA03DC6AF3");
assert!(uuid.is_some());

// Parse mixed case
let uuid = UUIDLike::parse_uuid_string("CaB1952a-F09D-86d9-928E-96ea03dc6af3");
assert!(uuid.is_some());

// Invalid format
assert!(UUIDLike::parse_uuid_string("not-a-uuid").is_none());

Trait Implementations§

Source§

impl Clone for UUIDLike

Source§

fn clone(&self) -> UUIDLike

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 UUIDLike

Source§

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

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

impl Hash for UUIDLike

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 UUIDLike

Source§

fn cmp(&self, other: &UUIDLike) -> 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 UUIDLike

Source§

fn eq(&self, other: &UUIDLike) -> 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 UUIDLike

Source§

fn partial_cmp(&self, other: &UUIDLike) -> 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 UUIDLike

Source§

impl Eq for UUIDLike

Source§

impl StructuralPartialEq for UUIDLike

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> 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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V