use std::fmt::{Debug, Display, Formatter};
use uuid::Uuid;
#[repr(transparent)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct HRESULT {
code: i32,
}
impl HRESULT {
pub const fn from_parts(is_error: bool, customer: bool, facility: u16, code: u16) -> HRESULT {
let is_error = if is_error { 1 << 31 } else { 0 };
let customer = if customer { 1 << 29 } else { 0 };
HRESULT {
code: is_error | customer | facility as i32 & 0x7FF << 16 | code as i32,
}
}
pub fn is_success(&self) -> bool {
self.code >= 0
}
pub fn is_error(&self) -> bool {
self.code < 0
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct GUID(pub u32, pub u16, pub u16, pub [u8; 8]);
impl GUID {
pub const ZERO: GUID = GUID(0, 0, 0, [0, 0, 0, 0, 0, 0, 0, 0]);
}
impl Default for GUID {
fn default() -> Self {
GUID::ZERO
}
}
impl Display for GUID {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&Uuid::from(*self), f)
}
}
impl From<GUID> for Uuid {
fn from(guid: GUID) -> Self {
Uuid::from_fields(guid.0, guid.1, guid.2, &guid.3)
}
}
impl From<Uuid> for GUID {
fn from(uuid: Uuid) -> Self {
let (u0, u1, u2, u3) = uuid.as_fields();
GUID(u0, u1, u2, *u3)
}
}
pub type IID = GUID;
pub type CLSID = GUID;