[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANiq72moSLXx7sRedN9Cjg-hWy4d8c1NfvmNyO-Uup+iupRF5w@mail.gmail.com>
Date: Wed, 19 Mar 2025 12:41:06 +0100
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Yury Norov <yury.norov@...il.com>, Burak Emir <bqe@...gle.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>, Viresh Kumar <viresh.kumar@...aro.org>,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Bjorn Roy Baron <bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 2/3] Adds Rust Bitmap API.
On Wed, Mar 19, 2025 at 11:40 AM Alice Ryhl <aliceryhl@...gle.com> wrote:
>
> Rewording `new` to `alloc` seems reasonable.
>
> As for "drop", that word is special. It's the destructor that is called
> automatically when the bitmap goes out of scope - you can't call it
> directly. It must be called "drop".
Alice obviously knows the following, but for so that Yury has the
context: `new` is the typical name in Rust for the "primary"
constructor, so that is probably Burak picked it, e.g. see:
https://rust-lang.github.io/api-guidelines/predictability.html#constructors-are-static-inherent-methods-c-ctor
Constructors in Rust are not special, and you can use any names (and
can return errors etc., unlike C++).
So people use `new` by convention since it is what others may look for
first in the documentation. It is especially nice if there is only a
single constructor, but not a big deal.
> But the confusion with "no set bits" seems like a good reason to silence
> that warning for bitmap.
Yeah, if a lint is giving trouble, please just disable it.
And if we need to disable it in quite a few places, we may just want
to disable it globally.
> We can still call the method __set_bit if you think that is best, but
> because underscore prefixes usually mean something different in Rust, I
> wonder if we should use slightly different names in Rust. Thoughts?
I would really prefer if we do our best to avoid underscores in Rust,
especially for non-private APIs.
In Linux we abuse `_+names` a bit sometimes to avoid writing a proper
name/prefix/suffix for the different variations of operations, and I
don't think it is a good idea to mimic that for non-private APIs. I
mean, for static single variations, it is OK-ish, but other cases are
not really great.
Worse, if we start doing that in Rust, we may start doing it for
things that do not even need to mimic a C API name...
Now, I know it is painful to have a different name than C, so it is a
trade-off. And sometimes coming up with names is difficult, too.
The underscore implying "possibly unused" is not too important for
`pub` APIs I think, since the compiler wouldn't warn about those
anyway, no? But for non-`pub` ones, I agree it is one more reason to
avoid it.
Cheers,
Miguel
Powered by blists - more mailing lists