> On 18 Feb 2025, at 10:00, Andreas Hindborg <a.hindb...@kernel.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.hindb...@kernel.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..ba6b1a5c4f99d 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 > + [u8]: Index<Idx, Output = [u8]>, > +{ > + type Output = Self; > + > + fn index(&self, index: Idx) -> &Self::Output { > + BStr::from_bytes(&self.0[index]) > + } > +} > + > /// Creates a new [`BStr`] from a string literal. > /// > /// `b_str!` converts the supplied string literal to byte string, so non-ASCII > > -- > 2.47.0 > > > Reviewed-by: Daniel Almeida <daniel.alme...@collabora.com>
- [PATCH v7 1/6] rust: str: implement `PartialEq` for `BStr... Andreas Hindborg
- Re: [PATCH v7 1/6] rust: str: implement `PartialEq` ... Daniel Almeida
- [PATCH v7 5/6] rust: str: add radix prefixed integer pars... Andreas Hindborg
- Re: [PATCH v7 5/6] rust: str: add radix prefixed int... Daniel Almeida
- Re: [PATCH v7 5/6] rust: str: add radix prefixed... Andreas Hindborg
- Re: [PATCH v7 5/6] rust: str: add radix prefixed int... Janne Grunau
- Re: [PATCH v7 5/6] rust: str: add radix prefixed... Miguel Ojeda
- Re: [PATCH v7 5/6] rust: str: add radix pref... Andreas Hindborg
- Re: [PATCH v7 5/6] rust: str: add radix prefixed... Andreas Hindborg
- [PATCH v7 2/6] rust: str: implement `Index` for `BStr` Andreas Hindborg
- Re: [PATCH v7 2/6] rust: str: implement `Index` for ... Daniel Almeida
- Re: [PATCH v7 2/6] rust: str: implement `Index` for ... Fiona Behrens
- [PATCH v7 6/6] rust: add parameter support to the `module... Andreas Hindborg
- Re: [PATCH v7 6/6] rust: add parameter support to th... Daniel Almeida
- Re: [PATCH v7 6/6] rust: add parameter support t... Andreas Hindborg
- Re: [PATCH v7 6/6] rust: add parameter support to th... Gary Guo
- Re: [PATCH v7 6/6] rust: add parameter support t... Andreas Hindborg
- [PATCH v7 3/6] rust: str: implement `AsRef<BStr>` f... Andreas Hindborg
- Re: [PATCH v7 3/6] rust: str: implement `AsRef<BS... Daniel Almeida
- Re: [PATCH v7 3/6] rust: str: implement `AsRef&l... Daniel Almeida
- Re: [PATCH v7 3/6] rust: str: implement `AsRef<BS... Gary Guo