Struct uefi::Guid

source ·
#[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

source

pub const ZERO: Guid = _

GUID with all fields set to zero.

source

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.

source

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);
source

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());
source

pub const fn time_low(self) -> [u8; 4]

The little-endian low field of the timestamp.

source

pub const fn time_mid(self) -> [u8; 2]

The little-endian middle field of the timestamp.

source

pub const fn time_high_and_version(self) -> [u8; 2]

The little-endian high field of the timestamp multiplexed with the version number.

source

pub const fn clock_seq_high_and_reserved(self) -> u8

The high field of the clock sequence multiplexed with the variant.

source

pub const fn clock_seq_low(self) -> u8

The low field of the clock sequence.

source

pub const fn node(self) -> [u8; 6]

The spatially unique node identifier.

source

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
);
source

pub const fn version(self) -> u8

Get the GUID version. This is a sub-type of the variant as defined in RFC4122.

§Example
use uguid::guid;

assert_eq!(guid!("308bbc16-a308-47e8-8977-5e5646c5291f").version(), 4);
source

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.

source

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.

source

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

Create a GUID from a 16-byte array. No changes to byte order are made.

source

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

Convert to a 16-byte array.

source

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 Clone for Guid

source§

fn clone(&self) -> Guid

Returns a copy 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 Guid

source§

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

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

impl Default for Guid

source§

fn default() -> Guid

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

impl Display for Guid

source§

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

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

impl FromStr for Guid

source§

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).

§

type Err = GuidFromStrError

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

impl Hash for Guid

source§

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

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 Guid

source§

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

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

impl PartialEq for Guid

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Guid

source§

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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Guid

source§

impl Eq for Guid

source§

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> 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> 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> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

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

§

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§

default 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>,

§

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>,

§

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.