aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorAlice Ryhl <aliceryhl@google.com>2023-05-02 12:40:15 +0000
committerMiguel Ojeda <ojeda@kernel.org>2023-05-31 18:53:10 +0200
commit4a59081c09cbfe17505baf3db50ebb9b97290bae (patch)
treee6fa3f0dc0f650ba8be998ed47ad41ddbd2de6a8 /rust
parent309786c2393c7b3375c232b137e52613c8099327 (diff)
downloadlinux-4a59081c09cbfe17505baf3db50ebb9b97290bae.tar.gz
rust: error: allow specifying error type on `Result`
Currently, if the `kernel::error::Result` type is in scope (which is often is, since it's in the kernel's prelude), you cannot write `Result<T, SomeOtherErrorType>` when you want to use a different error type than `kernel::error::Error`. To solve this we change the error type from being hard-coded to just being a default generic parameter. This still lets you write `Result<T>` when you just want to use the `Error` error type, but also lets you write `Result<T, SomeOtherErrorType>` when necessary. Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Asahi Lina <lina@asahilina.net> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://lore.kernel.org/r/20230502124015.356001-1-aliceryhl@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r--rust/kernel/error.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index 5f4114b30b94c7..01dd4d2f63d27a 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -177,7 +177,7 @@ impl From<core::convert::Infallible> for Error {
/// Note that even if a function does not return anything when it succeeds,
/// it should still be modeled as returning a `Result` rather than
/// just an [`Error`].
-pub type Result<T = ()> = core::result::Result<T, Error>;
+pub type Result<T = (), E = Error> = core::result::Result<T, E>;
/// Converts an integer as returned by a C kernel function to an error if it's negative, and
/// `Ok(())` otherwise.