diff options
| author | Wedson Almeida Filho <[email protected]> | 2022-11-10 16:41:22 +0000 |
|---|---|---|
| committer | Miguel Ojeda <[email protected]> | 2022-12-04 00:59:15 +0000 |
| commit | 76e2c2d9a22a402e816607ae575b1a194cc45a31 (patch) | |
| tree | eea7876a6b253f8d79efbc263935e0c29edfb5f8 /rust/alloc/vec/mod.rs | |
| parent | rust: error: add codes from `errno-base.h` (diff) | |
| download | kernel-76e2c2d9a22a402e816607ae575b1a194cc45a31.tar.gz kernel-76e2c2d9a22a402e816607ae575b1a194cc45a31.zip | |
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 <[email protected]>
Signed-off-by: Adam Bratschi-Kaye <[email protected]>
Co-developed-by: Nándor István Krácser <[email protected]>
Signed-off-by: Nándor István Krácser <[email protected]>
Signed-off-by: Wedson Almeida Filho <[email protected]>
Reviewed-by: Finn Behrens <[email protected]>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'rust/alloc/vec/mod.rs')
0 files changed, 0 insertions, 0 deletions
