From: Daniel Almeida <daniel.almeida@collabora.com>
To: Kari Argillander <kari.argillander@gmail.com>
Cc: "Filipe Xavier" <felipeaggger@gmail.com>,
"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>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
rust-for-linux@vger.kernel.org, felipe_life@live.com,
linux-kernel@vger.kernel.org, "Lyude Paul" <lyude@redhat.com>
Subject: Re: [PATCH v7] rust: add new macro for common bitmap operations
Date: Thu, 1 Jan 2026 17:22:45 -0300 [thread overview]
Message-ID: <E88301E9-6142-491A-ADA2-F3BD8D9B92EA@collabora.com> (raw)
In-Reply-To: <CAKBF=pu2RZOKztWHD-1Y-EY0-nQzc6JrwNheP3yA9fmyKS2fpg@mail.gmail.com>
> On 1 Jan 2026, at 16:14, Kari Argillander <kari.argillander@gmail.com> wrote:
>
> On Thu, 1 Jan 2026 at 20:21, Filipe Xavier <felipeaggger@gmail.com> wrote:
>
>> +/// // Combine multiple permissions using operation OR (`|`).
>> +/// let read_write: Permissions = Permission::Read | Permission::Write;
>> +///
>> +/// assert!(read_write.contains(Permission::Read));
>> +/// assert!(read_write.contains(Permission::Write));
>> +/// assert!(!read_write.contains(Permission::Execute));
>> +/// assert!(read_write.contains_any(Permission::Read | Permission::Execute));
>> +/// assert!(read_write.contains_all(Permission::Read | Permission::Write));
>> +///
>> +/// // Removing a permission with operation AND (`&`).
>> +/// let read_only: Permissions = read_write & Permission::Read;
>> +/// assert!(read_only.contains(Permission::Read));
>> +/// assert!(!read_only.contains(Permission::Write));
>> +///
>> +/// // Toggling permissions with XOR (`^`).
>> +/// let toggled: Permissions = read_only ^ Permission::Read;
>> +/// assert!(!toggled.contains(Permission::Read));
>> +///
>> +/// // Inverting permissions with negation (`!`).
>> +/// let negated = !read_only;
>> +/// assert!(negated.contains(Permission::Write));
>> +/// assert!(!negated.contains(Permission::Read));
>
> I really like the OR (`|`) operator. Personally, I don’t like anything
> else. When
> a function or expression gets longer, something like let negated = !read_only;
> already feels strange to read.
>
> My suggestion is that everything else should be functions, so we would write:
>
> ```rust
> let xxx = Permission::Read | Permission::Write;
> xxx.remove(Permission::Write | Permission::Read);
> xxx.toggle(Permission::Execute);
> xxx.invert();
> ```
>
> This way we avoid expressions like:
>
> ```rust
> let a = !(!xxx | yyy ^ zzz);
> ```
>
“
> At that point, no one understands what is really happening anymore. People start
> wondering whether operator precedence or evaluation order matters, and may even
> have to go read the source code to figure it out.
I disagree. How would that look like given your suggestion?
>
> By only supporting OR (|) as an operator and expressing everything else as
> explicit function calls, the code becomes much easier to read, review, and
> maintain.
>
> Argillander
How is A | B readable but not A & B or A ^ B?
next prev parent reply other threads:[~2026-01-01 20:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-01 18:21 Filipe Xavier
2026-01-01 19:14 ` Kari Argillander
2026-01-01 20:22 ` Daniel Almeida [this message]
2026-01-01 21:39 ` Kari Argillander
2026-01-01 22:50 ` Kari Argillander
2026-01-02 12:53 ` Gary Guo
2026-01-02 14:43 ` Daniel Almeida
2026-01-03 1:15 ` Kari Argillander
2026-01-03 14:00 ` Miguel Ojeda
2026-01-01 20:25 ` Daniel Almeida
2026-01-02 13:00 ` Gary Guo
2026-01-03 14:24 ` Miguel Ojeda
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=E88301E9-6142-491A-ADA2-F3BD8D9B92EA@collabora.com \
--to=daniel.almeida@collabora.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=felipe_life@live.com \
--cc=felipeaggger@gmail.com \
--cc=gary@garyguo.net \
--cc=kari.argillander@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lyude@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®