diff options
author | Wedson Almeida Filho <wedsonaf@gmail.com> | 2022-11-10 19:41:22 +0300 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2022-12-04 03:59:15 +0300 |
commit | 76e2c2d9a22a402e816607ae575b1a194cc45a31 (patch) | |
tree | eea7876a6b253f8d79efbc263935e0c29edfb5f8 /rust/kernel/lib.rs | |
parent | 266def2a0f5bbe44b11902bd4c93b9c5d8b8d708 (diff) | |
download | linux-76e2c2d9a22a402e816607ae575b1a194cc45a31.tar.xz |
rust: error: add `From` implementations for `Error`
Add a set of `From` implementations for the `Error` kernel type.
These implementations allow to easily convert from standard Rust
error types to the usual kernel errors based on one of the `E*`
integer codes.
On top of that, the question mark Rust operator (`?`) implicitly
performs a conversion on the error value using the `From` trait
when propagating. Thus it is extra convenient to use.
For instance, a kernel function that needs to convert a `i64` into
a `i32` and to bubble up the error as a kernel error may write:
fn f(x: i64) -> Result<...> {
...
let y = i32::try_from(x)?;
...
}
which will transform the `TryFromIntError` into an `Err(EINVAL)`.
Co-developed-by: Adam Bratschi-Kaye <ark.email@gmail.com>
Signed-off-by: Adam Bratschi-Kaye <ark.email@gmail.com>
Co-developed-by: Nándor István Krácser <bonifaido@gmail.com>
Signed-off-by: Nándor István Krácser <bonifaido@gmail.com>
Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Reviewed-by: Finn Behrens <me@kloenk.dev>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel/lib.rs')
-rw-r--r-- | rust/kernel/lib.rs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index abd46261d385..ffc6626a6d29 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -12,6 +12,7 @@ //! do so first instead of bypassing this crate. #![no_std] +#![feature(allocator_api)] #![feature(core_ffi_c)] // Ensure conditional compilation based on the kernel configuration works; |