Lines Matching full:errno
3 //! Utility functions to convert `errno` to and from
6 //! QEMU C functions often have a "positive success/negative `errno`" calling
12 /// An `errno` value that can be converted into an [`io::Error`]
13 pub struct Errno(pub u16); struct
15 // On Unix, from_raw_os_error takes an errno value and OS errors
17 // GetLastError() value; therefore we need to convert errno values
21 impl From<Errno> for ErrorKind {
22 fn from(value: Errno) -> ErrorKind { in from()
24 let Errno(errno) = value; in from() localVariable
25 match i32::from(errno) { in from()
50 impl From<io::ErrorKind> for Errno { implementation
51 fn from(value: io::ErrorKind) -> Errno { in from() argument
53 let errno = match value { in from() localVariable
73 Errno(errno as u16) in from()
77 impl From<Errno> for io::Error {
79 fn from(value: Errno) -> io::Error { in from()
80 let Errno(errno) = value; in from() localVariable
81 io::Error::from_raw_os_error(errno.into()) in from()
85 fn from(value: Errno) -> io::Error { in from()
91 impl From<io::Error> for Errno { implementation
92 fn from(value: io::Error) -> Errno { in from() argument
94 if let Some(errno) = value.raw_os_error() { in from()
95 return Errno(u16::try_from(errno).unwrap()); in from()
105 use super::Errno;
113 /// Return `Ok(self)` if positive, `Err(Errno(-self))` if negative
114 fn into_errno_result(self) -> Result<Self::Out, Errno>; in into_errno_result() argument
118 /// converted into "positive success/negative `errno`" convention.
132 fn into_errno_result(self) -> Result<Self::Out, Errno> {
135 -65535..=-1 => Err(Errno(-self as u16)),
136 _ => panic!("{self} is not a negative errno"),
176 /// are interpreted as negated `errno` and turned into an `Err`.
179 /// # use qemu_api::errno::into_io_result;
195 /// # use qemu_api::errno::into_io_result;
203 /// Convert a [`Result`] into an integer value, using negative `errno`
207 /// # use qemu_api::errno::into_neg_errno;
217 /// to an `errno` value, [`io::Result`] is the most commonly used type
226 /// # use qemu_api::errno::into_neg_errno;
232 pub fn into_neg_errno<T: MergeErrno, E: Into<Errno>>(value: Result<T, E>) -> T::Out { in into_neg_errno()