linux_unsafe/
result.rs

1//! Types representing results from system call wrapper functions.
2
3use crate::args::AsRawV;
4
5/// The result type used for all of the system call wrapper functions to
6/// distinguish between success and error results.
7pub type Result<T> = core::result::Result<T, Error>;
8
9/// Represents an error code directly from the kernel.
10#[derive(Clone, Copy, PartialEq, Eq, Debug)]
11#[repr(transparent)]
12pub struct Error(pub i32);
13
14impl Error {
15    #[inline(always)]
16    pub const fn new(raw: i32) -> Self {
17        Self(raw)
18    }
19}
20
21#[inline(always)]
22pub(crate) fn prepare_standard_result<T: AsRawV>(raw: crate::raw::V) -> Result<T> {
23    crate::raw::unpack_standard_result(raw)
24        .map(|raw| T::from_raw_result(raw))
25        .map_err(|raw| Error::new(raw))
26}
27
28#[inline(always)]
29pub(crate) fn prepare_arg<T: AsRawV>(arg: T) -> crate::raw::V {
30    arg.to_raw_arg()
31}
32
33pub use crate::raw::errno::*;