#[repr(C)]pub struct Guid { /* private fields */ }
Expand description
Globally-unique identifier.
The format is defined in RFC 4122. However, unlike “normal” UUIDs
(such as those provided by the uuid
crate), the first three
fields are little-endian. See also Appendix A of the UEFI
Specification.
This type is 4-byte aligned. The UEFI Specification says the GUID type should be 8-byte aligned, but most C implementations have 4-byte alignment, so we do the same here for compatibility.
Implementations§
source§impl Guid
impl Guid
sourcepub const fn new(
time_low: [u8; 4],
time_mid: [u8; 2],
time_high_and_version: [u8; 2],
clock_seq_high_and_reserved: u8,
clock_seq_low: u8,
node: [u8; 6],
) -> Guid
pub const fn new( time_low: [u8; 4], time_mid: [u8; 2], time_high_and_version: [u8; 2], clock_seq_high_and_reserved: u8, clock_seq_low: u8, node: [u8; 6], ) -> Guid
Create a new GUID.
sourcepub const fn from_random_bytes(random_bytes: [u8; 16]) -> Guid
pub const fn from_random_bytes(random_bytes: [u8; 16]) -> Guid
Create a version 4 GUID from provided random bytes.
See RFC 4122 section 4.4 for the definition of a version 4 GUID.
This constructor does not itself generate random bytes, but instead expects the caller to provide suitably random bytes.
§Example
use uguid::{Guid, Variant};
let guid = Guid::from_random_bytes([
104, 192, 95, 215, 120, 33, 249, 1, 102, 21, 171, 84, 233, 204, 68, 176,
]);
assert_eq!(guid.variant(), Variant::Rfc4122);
assert_eq!(guid.version(), 4);
sourcepub const fn is_zero(self) -> bool
pub const fn is_zero(self) -> bool
True if all bits are zero, false otherwise.
§Example
use uguid::guid;
assert!(guid!("00000000-0000-0000-0000-000000000000").is_zero());
assert!(!guid!("308bbc16-a308-47e8-8977-5e5646c5291f").is_zero());
sourcepub const fn time_high_and_version(self) -> [u8; 2]
pub const fn time_high_and_version(self) -> [u8; 2]
The little-endian high field of the timestamp multiplexed with the version number.
sourcepub const fn clock_seq_high_and_reserved(self) -> u8
pub const fn clock_seq_high_and_reserved(self) -> u8
The high field of the clock sequence multiplexed with the variant.
sourcepub const fn clock_seq_low(self) -> u8
pub const fn clock_seq_low(self) -> u8
The low field of the clock sequence.
sourcepub const fn variant(self) -> Variant
pub const fn variant(self) -> Variant
Get the GUID variant.
§Example
use uguid::{guid, Variant};
assert_eq!(
guid!("308bbc16-a308-47e8-8977-5e5646c5291f").variant(),
Variant::Rfc4122
);
sourcepub const fn try_parse(s: &str) -> Result<Guid, GuidFromStrError>
pub const fn try_parse(s: &str) -> Result<Guid, GuidFromStrError>
Parse a GUID from a string.
This is functionally the same as Self::from_str
, but is
exposed separately to provide a const
method for parsing.
sourcepub const fn parse_or_panic(s: &str) -> Guid
pub const fn parse_or_panic(s: &str) -> Guid
Parse a GUID from a string, panicking on failure.
The input must be in “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
format, where each x
is a hex digit (any of 0-9
, a-f
, or
A-F
).
This function is marked track_caller
so that error messages
point directly to the invalid GUID string.
§Panics
This function will panic if the input is not in the format shown above. In particular, it will panic if the input is not exactly 36 bytes long, or if the input does not have separators at the expected positions, or if any of the remaining characters are not valid hex digits.
sourcepub const fn from_bytes(bytes: [u8; 16]) -> Guid
pub const fn from_bytes(bytes: [u8; 16]) -> Guid
Create a GUID from a 16-byte array. No changes to byte order are made.
sourcepub const fn to_ascii_hex_lower(self) -> [u8; 36]
pub const fn to_ascii_hex_lower(self) -> [u8; 36]
Convert to a lower-case hex ASCII string.
The output is in “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx” format.
Trait Implementations§
source§impl FromStr for Guid
impl FromStr for Guid
source§fn from_str(s: &str) -> Result<Guid, <Guid as FromStr>::Err>
fn from_str(s: &str) -> Result<Guid, <Guid as FromStr>::Err>
Parse a GUID from a string, panicking on failure.
The input must be in “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”
format, where each x
is a hex digit (any of 0-9
, a-f
, or
A-F
).
source§type Err = GuidFromStrError
type Err = GuidFromStrError
source§impl Ord for Guid
impl Ord for Guid
source§impl PartialOrd for Guid
impl PartialOrd for Guid
impl Copy for Guid
impl Eq for Guid
impl StructuralPartialEq for Guid
Auto Trait Implementations§
impl Freeze for Guid
impl RefUnwindSafe for Guid
impl Send for Guid
impl Sync for Guid
impl Unpin for Guid
impl UnwindSafe for Guid
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)