> On 21 Feb 2025, at 13:01, Daniel Almeida <daniel.alme...@collabora.com> wrote: > > > >> On 18 Feb 2025, at 10:00, Andreas Hindborg <a.hindb...@kernel.org> wrote: >> >> Implement `AsRef<BStr>` for `[u8]` and `BStr` so these can be used >> interchangeably for operations on `BStr`. >> >> Signed-off-by: Andreas Hindborg <a.hindb...@kernel.org> >> --- >> rust/kernel/str.rs | 12 ++++++++++++ >> 1 file changed, 12 insertions(+) >> >> diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs >> index ba6b1a5c4f99d..c6bd2c69543dc 100644 >> --- a/rust/kernel/str.rs >> +++ b/rust/kernel/str.rs >> @@ -125,6 +125,18 @@ fn index(&self, index: Idx) -> &Self::Output { >> } >> } >> >> +impl AsRef<BStr> for [u8] { >> + fn as_ref(&self) -> &BStr { >> + BStr::from_bytes(self) >> + } >> +} >> + >> +impl AsRef<BStr> for BStr { >> + fn as_ref(&self) -> &BStr { >> + self >> + } >> +} > > Why do you need this last one? I see that this is used by the following patch. > >> + >> /// 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 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
- Re: [PATCH v7 0/6] rust: extend `module!` macro with inte... Daniel Almeida
- Re: [PATCH v7 0/6] rust: extend `module!` macro with... Andreas Hindborg
- Re: [PATCH v7 0/6] rust: extend `module!` macro with inte... Andreas Hindborg
- Re: [PATCH v7 0/6] rust: extend `module!` macro with... Petr Pavlu
- Re: [PATCH v7 0/6] rust: extend `module!` macro ... Miguel Ojeda
- Re: [PATCH v7 0/6] rust: extend `module!` ma... Petr Pavlu
- Re: [PATCH v7 0/6] rust: extend `module!... Miguel Ojeda