Skip to content

Commit 4b0c68b

Browse files
kloenkojeda
authored andcommitted
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 <[email protected]> Reviewed-by: Gary Guo <[email protected]> [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent b13c988 commit 4b0c68b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

rust/kernel/error.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@ use alloc::collections::TryReserveError;
88

99
/// Contains the C-compatible error codes.
1010
pub mod code {
11-
/// Out of memory.
12-
pub const ENOMEM: super::Error = super::Error(-(crate::bindings::ENOMEM as i32));
11+
macro_rules! declare_err {
12+
($err:tt $(,)? $($doc:expr),+) => {
13+
$(
14+
#[doc = $doc]
15+
)*
16+
pub const $err: super::Error = super::Error(-(crate::bindings::$err as i32));
17+
};
18+
}
19+
20+
declare_err!(ENOMEM, "Out of memory.");
1321
}
1422

1523
/// Generic integer kernel error.

0 commit comments

Comments
 (0)