use super::OSErr;
use std::num::NonZeroI32;
#[repr(transparent)]
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct OSStatus(NonZeroI32);
impl From<OSErr> for OSStatus {
#[inline]
fn from(error: OSErr) -> Self {
Self::from_os_err(error)
}
}
impl From<NonZeroI32> for OSStatus {
#[inline]
fn from(value: NonZeroI32) -> Self {
Self(value)
}
}
impl OSStatus {
#[inline]
pub const fn new(value: i32) -> Option<Self> {
match NonZeroI32::new(value) {
Some(value) => Some(Self(value)),
None => None,
}
}
#[inline]
pub const fn new_non_zero(value: NonZeroI32) -> Self {
Self(value)
}
#[inline]
pub const unsafe fn new_unchecked(value: i32) -> Self {
Self(NonZeroI32::new_unchecked(value))
}
#[inline]
pub const fn from_os_err(error: OSErr) -> Self {
unsafe { Self::new_unchecked(error.value() as i32) }
}
#[inline]
pub const fn value(self) -> i32 {
self.0.get()
}
#[inline]
pub const fn non_zero_value(self) -> NonZeroI32 {
self.0
}
}