diff options
author | Miguel Ojeda <ojeda@kernel.org> | 2025-08-29 21:22:41 +0200 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2025-09-10 00:10:10 +0200 |
commit | 58b4aa53606f75c7d6e6cd4710da4d4399e8f667 (patch) | |
tree | ae329843a71123a7832940bb3694f1fa923e9c6e /rust/kernel/error.rs | |
parent | 4fa9f72d657a76546849068b508a2c82983f8945 (diff) |
rust: error: improve `Error::from_errno` documentation
This constructor is public since commit 5ed147473458 ("rust: error:
make conversion functions public"), and we will refer to it from the
documentation of `to_result` in a later commit.
Thus improve its documentation, including adding examples.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel/error.rs')
-rw-r--r-- | rust/kernel/error.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index db14da976722..edd576b7dfe4 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -103,8 +103,23 @@ pub struct Error(NonZeroI32); impl Error { /// Creates an [`Error`] from a kernel error code. /// - /// It is a bug to pass an out-of-range `errno`. `EINVAL` would - /// be returned in such a case. + /// `errno` must be within error code range (i.e. `>= -MAX_ERRNO && < 0`). + /// + /// It is a bug to pass an out-of-range `errno`. [`code::EINVAL`] is returned in such a case. + /// + /// # Examples + /// + /// ``` + /// assert_eq!(Error::from_errno(-1), EPERM); + /// assert_eq!(Error::from_errno(-2), ENOENT); + /// ``` + /// + /// The following calls are considered a bug: + /// + /// ``` + /// assert_eq!(Error::from_errno(0), EINVAL); + /// assert_eq!(Error::from_errno(-1000000), EINVAL); + /// ``` pub fn from_errno(errno: crate::ffi::c_int) -> Error { if let Some(error) = Self::try_from_errno(errno) { error |