Re: [PATCH v2 2/2] rust: impl_flags: add bitwise operations with the underlying type
From: Miguel Ojeda
Date: Sat Jun 06 2026 - 07:24:07 EST
On Sat, Jun 6, 2026 at 10:09 AM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
> I feel like we already discussed this. I don't understand the objection.
Now that you mention it, yeah. Hmm... it may be have been a call.
> I have a C type integer that is a set of flags. In bindings, I
> manipulate the flags (I will send this code within the next few days):
Yeah, so what I suggested is that providing the before-and-after
(rather than "after" only below as you do here and in the commit
message) can help to justify it.
That is, what exactly would you need to do before this patch? i.e. do
you really need a temporary? e.g. could you have written `as ...`
(putting aside that we try to avoid casts) or are we missing something
else from your use case? Would a `From` instead be good enough
instead?
My reading of Gary's comment is that, by providing too convenient
operators on the raw type, people may avoid actually using the newtype
when it makes sense to do so (which is a general principle that I
agree with).
In your case, I can see it is reasonable to have the operator there
(to avoid either casts or , and I think we are still in a better spot
than C here (since we only implement it for a particular primitive
type etc.), but yeah, it should have a better justification -- it is a
tradeoff to introduce more convenience, and the patch doesn't really
discuss it or its alternatives.
I hope this clarifies.
Cheers,
Miguel