From: "Michael Büsch" <m@bues.ch>
To: Dirk Behme <dirk.behme@de.bosch.com>
Cc: <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH] [RFC] rust: error: Convert 0 being an error to Result
Date: Thu, 11 Jan 2024 07:59:57 +0100 [thread overview]
Message-ID: <20240111075957.09cc5129@barney> (raw)
In-Reply-To: <20240111064415.908487-1-dirk.behme@de.bosch.com>
[-- Attachment #1: Type: text/plain, Size: 522 bytes --]
On Thu, 11 Jan 2024 07:44:15 +0100
Dirk Behme <dirk.behme@de.bosch.com> wrote:
> +/// Converts an unsigned integer as returned by a C kernel function to EINVAL if it's zero,
> +/// and `Ok(u64)` otherwise.
> +pub fn to_result_zero(val: core::ffi::c_ulong) -> Result<u64> {
> + if val == 0 {
> + Err(code::EINVAL)
> + } else {
> + Ok(val)
> + }
> +}
Would it make sense to use Result<NonZeroU64> as a return type and make the function inline?
--
Michael Büsch
https://bues.ch/
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-01-11 7:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 6:44 [PATCH] [RFC] rust: error: Convert 0 being an error to Result Dirk Behme
2024-01-11 6:59 ` Greg KH
2024-01-11 7:29 ` Behme Dirk (CM/ESO2)
2024-01-11 7:54 ` Greg KH
2024-01-11 8:14 ` Behme Dirk (CM/ESO2)
2024-01-11 9:46 ` Trevor Gross
2024-01-11 12:17 ` Benno Lossin
2024-01-11 20:52 ` Trevor Gross
2024-01-11 6:59 ` Michael Büsch [this message]
2024-01-11 14:14 ` Alice Ryhl
2024-01-12 7:42 ` Behme Dirk (CM/ESO2)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240111075957.09cc5129@barney \
--to=m@bues.ch \
--cc=dirk.behme@de.bosch.com \
--cc=rust-for-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).