use core::fmt;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(C)]
pub struct Guid {
a: u32,
b: u16,
c: u16,
d: [u8; 8],
}
impl Guid {
pub const fn from_values(
time_low: u32,
time_mid: u16,
time_high_and_version: u16,
clock_seq_and_variant: u16,
node: [u8; 6],
) -> Self {
Guid {
a: time_low,
b: time_mid,
c: time_high_and_version,
d: [
(clock_seq_and_variant / 0x100) as u8,
(clock_seq_and_variant % 0x100) as u8,
node[0],
node[1],
node[2],
node[3],
node[4],
node[5],
],
}
}
}
impl fmt::Display for Guid {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let d = {
let (low, high) = (u16::from(self.d[0]), u16::from(self.d[1]));
(low << 8) | high
};
let e = self.d[2..8].iter().enumerate().fold(0, |acc, (i, &elem)| {
acc | {
let shift = (5 - i) * 8;
u64::from(elem) << shift
}
});
write!(
fmt,
"{:08x}-{:04x}-{:04x}-{:04x}-{:012x}",
self.a, self.b, self.c, d, e
)
}
}
pub unsafe trait Identify {
const GUID: Guid;
}
pub use uefi_macros::unsafe_guid;