diff options
author | Finn Behrens <me@kloenk.dev> | 2022-11-10 17:41:20 +0100 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2022-12-04 01:59:15 +0100 |
commit | 4b0c68bd0d8b0e23ab1763d4a6632720dd3f1a83 (patch) | |
tree | 4b0fa83c8260c2352244abb7f72fd6d9a563a9a2 /rust | |
parent | b13c9880f909ca5e406d9b3d061359fd8fb0c514 (diff) | |
download | lwn-4b0c68bd0d8b0e23ab1763d4a6632720dd3f1a83.tar.gz lwn-4b0c68bd0d8b0e23ab1763d4a6632720dd3f1a83.zip |
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: Finn Behrens <me@kloenk.dev>
Reviewed-by: Gary Guo <gary@garyguo.net>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r-- | rust/kernel/error.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 466b2a8fe569..b843f3445483 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -8,8 +8,16 @@ use alloc::collections::TryReserveError; /// 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. |