use crate::io::{ErrorKind, SimpleError, UnpackedError};
#[cfg(feature = "alloc")]
use crate::io::CustomError;
#[cfg(feature = "std")]
use crate::io::RawOsError;
#[cfg(all(not(target_os = "uefi"), target_pointer_width = "64"))]
use crate::io::PackedError;
#[cfg(feature = "alloc")]
use alloc::boxed::Box;
#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
pub(super) struct RawError {
#[cfg(all(not(target_os = "uefi"), target_pointer_width = "64"))]
packed: PackedError,
#[cfg(any(not(target_pointer_width = "64"), target_os = "uefi"))]
unpacked: UnpackedError,
}
impl RawError {
#[inline]
#[must_use]
pub const fn new_simple(message: &'static SimpleError) -> Self {
#[cfg(all(not(target_os = "uefi"), target_pointer_width = "64"))]
{ Self { packed: PackedError::new_simple(message) } }
#[cfg(any(not(target_pointer_width = "64"), target_os = "uefi"))]
{ Self { unpacked: UnpackedError::Simple(message) } }
}
#[inline]
#[must_use]
pub fn new_inline(kind: ErrorKind) -> Self {
#[cfg(all(not(target_os = "uefi"), target_pointer_width = "64"))]
{ Self { packed: PackedError::new_inline(kind) } }
#[cfg(any(not(target_pointer_width = "64"), target_os = "uefi"))]
{ Self { unpacked: UnpackedError::Inline(kind) } }
}
#[cfg(feature = "alloc")]
#[inline]
#[must_use]
pub fn new_custom(custom: Box<CustomError>) -> Self {
#[cfg(all(not(target_os = "uefi"), target_pointer_width = "64"))]
{ Self { packed: PackedError::new_custom(custom) } }
#[cfg(any(not(target_pointer_width = "64"), target_os = "uefi"))]
{
let custom = Box::into_raw(custom);
{ Self { unpacked: UnpackedError::Custom(custom) } }
}
}
#[cfg(feature = "std")]
#[inline]
#[must_use]
pub fn new_os(raw: RawOsError) -> Self {
#[cfg(all(not(target_os = "uefi"), target_pointer_width = "64"))]
{ Self { packed: PackedError::new_os(raw) } }
#[cfg(any(not(target_pointer_width = "64"), target_os = "uefi"))]
{ Self { unpacked: UnpackedError::Os(raw) } }
}
#[inline]
#[must_use]
pub fn unpack(self) -> UnpackedError {
#[cfg(all(not(target_os = "uefi"), target_pointer_width = "64"))]
{ self.packed.unpack() }
#[cfg(any(not(target_pointer_width = "64"), target_os = "uefi"))]
{ self.unpacked }
}
}