[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250212090914.6ef7e83b@eugeo>
Date: Wed, 12 Feb 2025 09:09:14 +0000
From: Gary Guo <gary@...yguo.net>
To: Andreas Hindborg <a.hindborg@...nel.org>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
<alex.gaynor@...il.com>, "Boqun Feng" <boqun.feng@...il.com>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
<benno.lossin@...ton.me>, "Alice Ryhl" <aliceryhl@...gle.com>, "Masahiro
Yamada" <masahiroy@...nel.org>, "Nathan Chancellor" <nathan@...nel.org>,
"Nicolas Schier" <nicolas@...sle.eu>, "Luis Chamberlain"
<mcgrof@...nel.org>, "Trevor Gross" <tmgross@...ch.edu>, "Adam
Bratschi-Kaye" <ark.email@...il.com>, <rust-for-linux@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <linux-kbuild@...r.kernel.org>, "Petr
Pavlu" <petr.pavlu@...e.com>, "Sami Tolvanen" <samitolvanen@...gle.com>,
"Daniel Gomez" <da.gomez@...sung.com>, "Simona Vetter"
<simona.vetter@...ll.ch>, "Greg KH" <gregkh@...uxfoundation.org>,
<linux-modules@...r.kernel.org>
Subject: Re: [PATCH v6 2/6] rust: str: implement `Index` for `BStr`
On Tue, 11 Feb 2025 21:24:44 +0100
Andreas Hindborg <a.hindborg@...nel.org> wrote:
> "Gary Guo" <gary@...yguo.net> writes:
>
> > On Tue, 11 Feb 2025 16:57:36 +0100
> > Andreas Hindborg <a.hindborg@...nel.org> wrote:
> >
> >> The `Index` implementation on `BStr` was lost when we switched `BStr` from
> >> a type alias of `[u8]` to a newtype. This patch adds back `Index` by
> >> implementing `Index` for `BStr` when `Index` would be implemented for
> >> `[u8]`.
> >>
> >> Signed-off-by: Andreas Hindborg <a.hindborg@...nel.org>
> >> ---
> >> rust/kernel/str.rs | 11 +++++++++++
> >> 1 file changed, 11 insertions(+)
> >>
> >> diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
> >> index 002dcddf7c768..1eb945bed77d6 100644
> >> --- a/rust/kernel/str.rs
> >> +++ b/rust/kernel/str.rs
> >> @@ -114,6 +114,17 @@ fn eq(&self, other: &Self) -> bool {
> >> }
> >> }
> >>
> >> +impl<Idx> Index<Idx> for BStr
> >> +where
> >> + Idx: core::slice::SliceIndex<[u8], Output = [u8]>,
> >
> > I think I'd prefer
> >
> > [T]: Index<Idx>,
>
> Is that equivalent?
Sorry, I meant `[u8]: Index<Idx>`. This makes more semantic sense that
"what ever can index a byte slice, it can also index BStr". This is
also how our CStr and the array primitive type implements its Index
operation.
They should be equivalent as libcore does
impl<T, I> Index<I> for [T] where I: SliceIndex<[T]> { ... }
Best,
Gary
>
>
> Best regards,
> Andreas Hindborg
>
>
Powered by blists - more mailing lists