Commit 4b0c68bd authored by Finn Behrens's avatar Finn Behrens Committed by Miguel Ojeda
Browse files

rust: error: declare errors using macro



Add a macro to declare errors, which simplifies the work needed to
add each one, avoids repetition of the code and makes it easier to
change the way they are declared.

Signed-off-by: default avatarFinn Behrens <me@kloenk.dev>
Reviewed-by: default avatarGary Guo <gary@garyguo.net>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent b13c9880
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -8,8 +8,16 @@

/// Contains the C-compatible error codes.
pub mod code {
    /// Out of memory.
    pub const ENOMEM: super::Error = super::Error(-(crate::bindings::ENOMEM as i32));
    macro_rules! declare_err {
        ($err:tt $(,)? $($doc:expr),+) => {
            $(
            #[doc = $doc]
            )*
            pub const $err: super::Error = super::Error(-(crate::bindings::$err as i32));
        };
    }

    declare_err!(ENOMEM, "Out of memory.");
}

/// Generic integer kernel error.