stdlib/uuidView source ↗
uuid
13 items · generated by scribe fromstdlib/uuid.fd· synced 2026-11-15
Contents
- UUID (struct)
- uuid_v4 (function)
- uuid_nil (function)
- uuid_from_bytes (function)
- uuid_to_string (function)
- uuid_to_string_upper (function)
- uuid_to_urn (function)
- uuid_parse (function)
- uuid_equal (function)
- uuid_is_nil (function)
- uuid_version (function)
- uuid_variant (function)
UUID
A 128-bit UUID stored as 16 bytes in a Vec.
pub struct UUID {Fields:
| Name | Type |
|---|---|
bytes | Vec<i64> |
Defined at line 17
uuid_v4
Generate a random UUID v4. Uses random_int_range for each byte, then sets the version and variant bits.
Example: var u = uuid_v4(); var s = uuid_to_string(u); println(s); assert_eq(str_len(s), 36); assert_eq(uuid_version(u), 4); assert_eq(uuid_variant(u), 1); assert(!uuid_equal(u, uuid_v4()));
pub fn uuid_v4() -> UUID {Returns: UUID
Defined at line 34
uuid_nil
Generate a nil UUID (all zeros).
Example: assert_eq(uuid_to_string(uuid_nil()), “00000000-0000-0000-0000-000000000000”);
pub fn uuid_nil() -> UUID {Returns: UUID
Defined at line 56
uuid_from_bytes
Generate a UUID from a Vec of 16 bytes.
Example: var b: Vec
pub fn uuid_from_bytes(bytes: Vec<i64>) -> UUID {Parameters:
bytes:Vec<i64>
Returns: UUID
Defined at line 75
uuid_to_string
Format a UUID as a lowercase string: “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
Example: var u = uuid_parse(“123E4567-E89B-12D3-A456-426614174000”); assert_eq(uuid_to_string(u), “123e4567-e89b-12d3-a456-426614174000”);
pub fn uuid_to_string(u: UUID) -> str {Parameters:
u:UUID
Returns: str
Defined at line 96
uuid_to_string_upper
Format a UUID as an uppercase string.
Example: var u = uuid_parse(“123e4567e89b12d3a456426614174000”); assert_eq(uuid_to_string_upper(u), “123E4567-E89B-12D3-A456-426614174000”);
pub fn uuid_to_string_upper(u: UUID) -> str {Parameters:
u:UUID
Returns: str
Defined at line 118
uuid_to_urn
Format a UUID as a URN: “urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
Example: assert_eq(uuid_to_urn(uuid_nil()), “urn:uuid:00000000-0000-0000-0000-000000000000”);
pub fn uuid_to_urn(u: UUID) -> str {Parameters:
u:UUID
Returns: str
Defined at line 127
uuid_parse
Parse a UUID string (with or without hyphens). Returns a UUID, or nil UUID if invalid.
Example: var u = uuid_parse(“123e4567-e89b-12d3-a456-426614174000”); assert_eq(uuid_version(u), 1); assert(uuid_is_nil(uuid_parse(“not-a-uuid”)));
pub fn uuid_parse(s: str) -> UUID {Parameters:
s:str
Returns: UUID
Defined at line 140
uuid_equal
Check if two UUIDs are equal.
Example: var a = uuid_parse(“123e4567-e89b-12d3-a456-426614174000”); var b = uuid_parse(“123e4567e89b12d3a456426614174000”); assert(uuid_equal(a, b));
pub fn uuid_equal(a: UUID, b: UUID) -> bool {Parameters:
a:UUIDb:UUID
Returns: bool
Defined at line 186
uuid_is_nil
Check if a UUID is the nil UUID.
Example: assert(uuid_is_nil(uuid_nil()));
pub fn uuid_is_nil(u: UUID) -> bool {Parameters:
u:UUID
Returns: bool
Defined at line 201
uuid_version
Get the version of a UUID (1-5, or 0 for nil).
Example: assert_eq(uuid_version(uuid_nil()), 0);
pub fn uuid_version(u: UUID) -> i64 {Parameters:
u:UUID
Returns: i64
Defined at line 216
uuid_variant
Get the variant of a UUID. Returns: 0 (NCS), 1 (RFC 4122), 2 (Microsoft), 3 (reserved).
Example: assert_eq(uuid_variant(uuid_parse(“123e4567-e89b-12d3-a456-426614174000”)), 1);
pub fn uuid_variant(u: UUID) -> i64 {Parameters:
u:UUID
Returns: i64
Defined at line 225
Generated by scribe, the Fides documentation generator