Re: [PATCH v6 2/6] rust: str: implement `Index` for `BStr`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Gary Guo" <gary@xxxxxxxxxxx> writes:

> On Tue, 11 Feb 2025 16:57:36 +0100
> Andreas Hindborg <a.hindborg@xxxxxxxxxx> 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@xxxxxxxxxx>
>> ---
>>  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?


Best regards,
Andreas Hindborg






[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux