Re: [PATCH] rust: time: implement `Display` for `Delta`

From: Andreas Hindborg

Date: Mon May 11 2026 - 10:29:44 EST


Alice Ryhl <aliceryhl@xxxxxxxxxx> writes:

> On Sun, Feb 15, 2026 at 09:14:05PM +0100, Andreas Hindborg wrote:
>> Implement the `Display` trait for `Delta` so that it can be displayed by a
>> formatter.
>>
>> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>> ---
>> rust/kernel/time.rs | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
>> index 6ea98dfcd0278..e18fd17f38c5a 100644
>> --- a/rust/kernel/time.rs
>> +++ b/rust/kernel/time.rs
>> @@ -474,3 +474,9 @@ pub fn rem_nanos(self, dividend: i32) -> Self {
>> }
>> }
>> }
>> +
>> +impl kernel::fmt::Display for Delta {
>> + fn fmt(&self, f: &mut kernel::fmt::Formatter<'_>) -> kernel::fmt::Result {
>> + f.write_fmt(kernel::prelude::fmt!("{}", self.as_nanos()))
>
> I think this can just be
>
> self.as_nanos().fmt(f)
>
> Though I think it would be nicer to include an 'ns' suffix here so it's
> not just the number?

I was planning to use this to format a delta to output via a configfs in
rnull. The existing C driver does not include the "ns" suffix, which is
why I did not either.

I am not opposed to adding the suffix for this particular
implementation, but that would mean my user for this code will no longer
be a user, and I would drop the patch in favor of another solution at
the call site.

Please advise which of the following make most sense:

- Merge this patch without a suffix.
- Iterate on this patch and merge it without a user.
- Drop this patch for now.


Best regards,
Andreas Hindborg