Skip to main content

Module uuid

Module uuid 

Source
Available on crate feature net only.
Expand description

UUID type for network programming.

This module provides a type-safe abstraction for UUIDs, ensuring compliance with RFC 4122 UUID specifications.

§RFC 4122 UUID Rules

According to RFC 4122:

  • Length: 16 bytes (128 bits)
  • Format: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX (8-4-4-4-12 hex digits)
  • Versions: 1 (time-based), 3 (MD5), 4 (random), 5 (SHA-1)
  • Variants: NCS, RFC 4122, Microsoft, Future
  • Nil UUID: 00000000-0000-0000-0000-000000000000

§Examples

use bare_types::net::Uuid;

// Create a UUID from bytes
let uuid = Uuid::new([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
                       0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff]);

// Check if it's nil
assert!(!uuid.is_nil());

// Get the version
assert_eq!(uuid.version(), None);

// Get the string representation
assert_eq!(uuid.as_str(), "00112233-4455-6677-8899-aabbccddeeff");

// Parse from string
let uuid: Uuid = "00112233-4455-6677-8899-aabbccddeeff".parse()?;

Structs§

Uuid
A UUID.

Enums§

UuidError
Error type for UUID validation.
UuidVariant
UUID variant.