Skip to content

Commit 4a59081

Browse files
Darksonnojeda
authored andcommitted
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>
1 parent 309786c commit 4a59081

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rust/kernel/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl From<core::convert::Infallible> for Error {
177177
/// Note that even if a function does not return anything when it succeeds,
178178
/// it should still be modeled as returning a `Result` rather than
179179
/// just an [`Error`].
180-
pub type Result<T = ()> = core::result::Result<T, Error>;
180+
pub type Result<T = (), E = Error> = core::result::Result<T, E>;
181181

182182
/// Converts an integer as returned by a C kernel function to an error if it's negative, and
183183
/// `Ok(())` otherwise.

0 commit comments

Comments
 (0)