Skip to content
Snippets Groups Projects
Verified Commit b9653e68 authored by Jacob Lorentzon's avatar Jacob Lorentzon
Browse files

Implement From<Errno> for io::Error.

parent 4bd0d2a1
No related branches found
No related tags found
No related merge requests found
...@@ -7,17 +7,26 @@ pub struct Errno(pub c_int); ...@@ -7,17 +7,26 @@ pub struct Errno(pub c_int);
#[cfg(target_os = "redox")] #[cfg(target_os = "redox")]
impl From<syscall::Error> for Errno { impl From<syscall::Error> for Errno {
#[inline]
fn from(value: syscall::Error) -> Self { fn from(value: syscall::Error) -> Self {
Errno(value.errno) Errno(value.errno)
} }
} }
#[cfg(target_os = "redox")] #[cfg(target_os = "redox")]
impl From<Errno> for syscall::Error { impl From<Errno> for syscall::Error {
#[inline]
fn from(value: Errno) -> Self { fn from(value: Errno) -> Self {
syscall::Error::new(value.0) syscall::Error::new(value.0)
} }
} }
impl From<Errno> for crate::io::Error {
#[inline]
fn from(Errno(errno): Errno) -> Self {
Self::from_raw_os_error(errno)
}
}
pub trait ResultExt<T> { pub trait ResultExt<T> {
fn or_minus_one_errno(self) -> T; fn or_minus_one_errno(self) -> T;
} }
...@@ -25,10 +34,10 @@ impl<T: From<i8>> ResultExt<T> for Result<T, Errno> { ...@@ -25,10 +34,10 @@ impl<T: From<i8>> ResultExt<T> for Result<T, Errno> {
fn or_minus_one_errno(self) -> T { fn or_minus_one_errno(self) -> T {
match self { match self {
Self::Ok(v) => v, Self::Ok(v) => v,
Self::Err(Errno(errno)) => unsafe { Self::Err(Errno(errno)) => {
crate::platform::ERRNO.set(errno); crate::platform::ERRNO.set(errno);
T::from(-1) T::from(-1)
}, }
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment