Re: [PATCH v3 02/12] rust: xarray: add debug format for `StoreError`

From: Andreas Hindborg

Date: Tue Feb 24 2026 - 08:57:35 EST


Tamir Duberstein <tamird@xxxxxxxxx> writes:

> On Tue, Feb 10, 2026 at 8:45 AM Daniel Gomez <da.gomez@xxxxxxxxxx> wrote:
>>
>> On 2026-02-09 15:38, Andreas Hindborg wrote:
>> > Add a `Debug` implementation for `StoreError<T>` to enable better error
>> > reporting and debugging. The implementation only displays the `error`
>> > field and omits the `value` field, as `T` may not implement `Debug`.
>> >
>> > Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
>> > Acked-by: Tamir Duberstein <tamird@xxxxxxxxx>
>> > Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>> > ---
>> > rust/kernel/xarray.rs | 8 ++++++++
>> > 1 file changed, 8 insertions(+)
>> >
>> > diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
>> > index 88625c9abf4ef..d9762c6bef19c 100644
>> > --- a/rust/kernel/xarray.rs
>> > +++ b/rust/kernel/xarray.rs
>> > @@ -193,6 +193,14 @@ pub struct StoreError<T> {
>> > pub value: T,
>> > }
>> >
>> > +impl<T> core::fmt::Debug for StoreError<T> {
>> > + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
>> > + f.debug_struct("StoreError")
>> > + .field("error", &self.error)
>> > + .finish()
>> > + }
>> > +}
>> > +
>>
>> Is there any best practice for when to include use core::fmt::*, so you can
>> avoid being verbose here?
>>
>> I see other cases like this, but I couldn't find anything in the code
>> guidelines.

I don't think there is a best practice here. I feel that if we only
invoke a path a few times, we might as well write it out at the use site
rather than clobber the name space of the compilation unit.

>
> It would probably be better to use kernel::fmt::* rather than
> core::fmt so that we can interpose our own trait in the future, if we
> want.

I'll change to `kernel::fmt::*`.

Best regards,
Andreas Hindborg