From: Alice Ryhl <aliceryhl@google.com>
To: Andreas Hindborg <a.hindborg@kernel.org>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Lyude Paul" <lyude@redhat.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"John Stultz" <jstultz@google.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] rust: time: implement `Debug` for `Delta`
Date: Thu, 26 Nov 2026 12:59:37 +0000 [thread overview]
Message-ID: <20261126125937.3973192-1-aliceryhl@google.com> (raw)
In-Reply-To: <20261126-time-delta-display-v3-1-aeeecc72f3a8@kernel.org>
On Thu, Nov 26, 2026 at 11:51:14AM +0100, Andreas Hindborg wrote:
> Implement the `Debug` trait for `Delta` so that a span of time can be
> printed by a formatter.
>
> The span is printed as a count of the time unit it is stored in, suffixed
> with that unit, and with each group of three digits separated by an
> underscore the way Rust integer literals are written. A span of 12345
> nanoseconds is printed as `12_345 ns`.
>
> `Debug` is implemented rather than `Display`, because `Delta` has no single
> obvious format and the other kernel types that carry a unit, `Hertz`,
> `MicroVolt` and `MicroWatt`, implement `Debug` only. Callers that need a
> specific format should use `Delta::as_nanos` and print the result
> themselves.
Thanks for addressing the earlier feedback! Aside from the 32-bit division
issue that Tomonori already pointed out, this looks good to me.
> + #[inline]
> + fn repr_to_i64(repr: Self::Repr) -> i64 {
> + // CAST: `isize` is 32 or 64 bits wide on the architectures the kernel
> + // supports, so widening to `i64` preserves the value.
> + repr as i64
> + }
Maybe we could add `impl FromSafeCast<isize> for i64` to
`kernel::num::casts` and use `i64::from_safe_cast(repr)` here?
> + let mut groups = [0u64; 7];
Minor nit: since each group is `< 1000`, this could be `[0u16; 7]` instead
of `[0u64; 7]`.
Alice
next prev parent reply other threads:[~2026-11-26 12:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 10:51 Andreas Hindborg
2026-11-26 11:25 ` FUJITA Tomonori
2026-11-26 12:01 ` Andreas Hindborg
2026-11-26 12:59 ` Alice Ryhl [this message]
2026-11-26 13:31 ` Andreas Hindborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126125937.3973192-1-aliceryhl@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=anna-maria@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tamird@kernel.org \
--cc=tglx@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®