use crate::backend;
use core::{fmt, result};
#[cfg(feature = "std")]
use std::error;
pub type Result<T> = result::Result<T, Errno>;
pub use backend::io::errno::Errno;
impl Errno {
#[cfg(feature = "std")]
#[inline]
pub fn kind(self) -> std::io::ErrorKind {
std::io::Error::from(self).kind()
}
}
impl fmt::Display for Errno {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(feature = "std")]
{
std::io::Error::from(*self).fmt(f)
}
#[cfg(not(feature = "std"))]
{
write!(f, "os error {}", self.raw_os_error())
}
}
}
impl fmt::Debug for Errno {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(feature = "std")]
{
std::io::Error::from(*self).fmt(f)
}
#[cfg(not(feature = "std"))]
{
write!(f, "os error {}", self.raw_os_error())
}
}
}
#[cfg(feature = "std")]
impl error::Error for Errno {}
#[cfg(feature = "std")]
impl From<Errno> for std::io::Error {
#[inline]
fn from(err: Errno) -> Self {
Self::from_raw_os_error(err.raw_os_error() as _)
}
}
#[inline]
pub fn retry_on_intr<T, F: FnMut() -> Result<T>>(mut f: F) -> Result<T> {
loop {
match f() {
Err(Errno::INTR) => (),
result => return result,
}
}
}