All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Benno Lossin" <benno.lossin@proton.me>,
	"Danilo Krummrich" <dakr@kernel.org>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust/revocable: add try_with() convenience method
Date: Sun, 16 Mar 2025 21:20:03 +0900	[thread overview]
Message-ID: <D8HOP09FU367.2MVDRQ5G0OPV@nvidia.com> (raw)
In-Reply-To: <D8H11HOL93UD.31F853PYJA9U2@proton.me>

On Sun Mar 16, 2025 at 2:48 AM JST, Benno Lossin wrote:
> On Sat Mar 15, 2025 at 3:26 PM CET, Alexandre Courbot wrote:
>> On Sat Mar 15, 2025 at 11:17 PM JST, Danilo Krummrich wrote:
>>> On Sat, Mar 15, 2025 at 11:07:44PM +0900, Alexandre Courbot wrote:
>>>> I suppose drivers could add their own macros to do that automatically
>>>> and reduce code verbosity, at the cost of less cohesion across drivers.
>>>> Guess I'll go with that if I cannot come with anything better.
>>>
>>> Maybe we could do something more specific but yet generic on top (for the
>>> use-case above), but we still can't assume the exact error code a driver wants
>>> to derive from failing try_access(). So, maybe a driver specific wrapper is
>>> indeed what you want on top of what this patch provides.
>>
>> So be it! It's not that bad and more flexible in the end.
>
> You could have the following signature:
>
>     fn try_access_with<R>(&self, on_vacant: Error, f: impl FnOnce(&T) -> Result<R>) -> Result<R>;
>
> That will use the `on_vacant` error instead of hard coding ENXIO. But
> maybe it's better to just have such a wrapper in drivers that actually
> need it (ie even with the concrete error specified and not a parameter).
> You'll know better through actually trying to write a driver.

Yeah, having the extra on_vacant parameter would require callers to
specify the error they need every time, where it is supposed to be
a per-driver constant. So I guess a per-driver macro or wrapper would be
more ergonomic in the end.

  reply	other threads:[~2025-03-16 12:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 12:40 [PATCH] rust/revocable: add try_with() convenience method Alexandre Courbot
2025-03-13 14:19 ` Benno Lossin
2025-03-13 15:08   ` Alexandre Courbot
2025-03-13 15:38     ` Benno Lossin
2025-03-13 15:48       ` Danilo Krummrich
2025-03-13 17:50         ` Benno Lossin
2025-03-15 14:07           ` Alexandre Courbot
2025-03-15 14:17             ` Danilo Krummrich
2025-03-15 14:26               ` Alexandre Courbot
2025-03-15 17:48                 ` Benno Lossin
2025-03-16 12:20                   ` Alexandre Courbot [this message]
2025-03-16 12:42                     ` Danilo Krummrich
2025-03-13 14:37 ` Danilo Krummrich
2025-03-13 15:11   ` Alexandre Courbot

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=D8HOP09FU367.2MVDRQ5G0OPV@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.