Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+17 -2
+17 -2
rust/kernel/error.rs
··· 103 103 impl Error { 104 104 /// Creates an [`Error`] from a kernel error code. 105 105 /// 106 - /// It is a bug to pass an out-of-range `errno`. `EINVAL` would 107 - /// be returned in such a case. 106 + /// `errno` must be within error code range (i.e. `>= -MAX_ERRNO && < 0`). 107 + /// 108 + /// It is a bug to pass an out-of-range `errno`. [`code::EINVAL`] is returned in such a case. 109 + /// 110 + /// # Examples 111 + /// 112 + /// ``` 113 + /// assert_eq!(Error::from_errno(-1), EPERM); 114 + /// assert_eq!(Error::from_errno(-2), ENOENT); 115 + /// ``` 116 + /// 117 + /// The following calls are considered a bug: 118 + /// 119 + /// ``` 120 + /// assert_eq!(Error::from_errno(0), EINVAL); 121 + /// assert_eq!(Error::from_errno(-1000000), EINVAL); 122 + /// ``` 108 123 pub fn from_errno(errno: crate::ffi::c_int) -> Error { 109 124 if let Some(error) = Self::try_from_errno(errno) { 110 125 error