use core::fmt;
use core::num::{NonZeroI32, NonZeroI64, NonZeroIsize};
use crate::errno::EINTR;
use crate::Errno;
impl From<Errno> for i32 {
#[inline(always)]
fn from(ec: Errno) -> i32 {
ec.get()
}
}
impl From<Errno> for NonZeroI32 {
#[inline(always)]
fn from(ec: Errno) -> Self {
ec.get_nonzero()
}
}
impl From<Errno> for i64 {
#[inline(always)]
fn from(ec: Errno) -> Self {
ec.get() as u32 as Self
}
}
impl From<Errno> for NonZeroI64 {
#[inline(always)]
fn from(ec: Errno) -> Self {
unsafe { Self::new_unchecked(ec.get() as u32 as i64) }
}
}
impl fmt::Binary for Errno {
#[inline(always)]
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.get().fmt(fmt)
}
}
impl fmt::LowerHex for Errno {
#[inline(always)]
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.get().fmt(fmt)
}
}
impl fmt::UpperHex for Errno {
#[inline(always)]
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.get().fmt(fmt)
}
}
impl PartialEq<i32> for Errno {
#[inline(always)]
fn eq(&self, other: &i32) -> bool {
self.get() == *other
}
}
impl PartialEq<Errno> for i32 {
#[inline(always)]
fn eq(&self, other: &Errno) -> bool {
*self == other.get()
}
}
impl PartialEq<NonZeroI32> for Errno {
#[inline(always)]
fn eq(&self, other: &NonZeroI32) -> bool {
self.get() == other.get()
}
}
impl PartialEq<Errno> for NonZeroI32 {
#[inline(always)]
fn eq(&self, other: &Errno) -> bool {
self.get() == other.get()
}
}
impl PartialEq<i64> for Errno {
#[inline(always)]
fn eq(&self, other: &i64) -> bool {
self.get() as u32 as i64 == *other
}
}
impl PartialEq<Errno> for i64 {
#[inline(always)]
fn eq(&self, other: &Errno) -> bool {
*self == other.get() as u32 as i64
}
}
impl PartialEq<NonZeroI64> for Errno {
#[inline(always)]
fn eq(&self, other: &NonZeroI64) -> bool {
self.get() as u32 as i64 == other.get()
}
}
impl PartialEq<Errno> for NonZeroI64 {
#[inline(always)]
fn eq(&self, other: &Errno) -> bool {
self.get() == other.get() as u32 as i64
}
}
impl PartialEq<isize> for Errno {
#[inline(always)]
fn eq(&self, other: &isize) -> bool {
self.get() as u32 as isize == *other
}
}
impl PartialEq<Errno> for isize {
#[inline(always)]
fn eq(&self, other: &Errno) -> bool {
*self == other.get() as u32 as isize
}
}
impl PartialEq<NonZeroIsize> for Errno {
#[inline(always)]
fn eq(&self, other: &NonZeroIsize) -> bool {
self.get() as u32 as isize == other.get()
}
}
impl PartialEq<Errno> for NonZeroIsize {
#[inline(always)]
fn eq(&self, other: &Errno) -> bool {
self.get() == other.get() as u32 as isize
}
}
#[cfg(feature = "std")]
impl From<Errno> for std::io::Error {
#[inline(always)]
fn from(ec: Errno) -> Self {
Self::from_raw_os_error(ec.get())
}
}
pub fn retry_eintr<T>(mut f: impl FnMut() -> Result<T, Errno>) -> Result<T, Errno> {
loop {
match f() {
Err(EINTR) => continue,
r => return r,
}
}
}