From: Andreas Hindborg <a.hindborg@kernel.org>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: fujita.tomonori@gmail.com, lyude@redhat.com,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
boqun.feng@gmail.com, frederic@kernel.org, tglx@linutronix.de,
anna-maria@linutronix.de, jstultz@google.com, sboyd@kernel.org,
ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org
Subject: Re: [PATCH] rust/time: Add Delta::from_nanos()
Date: Mon, 17 Nov 2025 13:26:44 +0100 [thread overview]
Message-ID: <87qztw26bf.fsf@metaspace.dk> (raw)
In-Reply-To: <20251117.203843.1397954301918831869.fujita.tomonori@gmail.com>
"FUJITA Tomonori" <fujita.tomonori@gmail.com> writes:
> On Mon, 17 Nov 2025 12:15:53 +0100
> Andreas Hindborg <a.hindborg@kernel.org> wrote:
>
>>>> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
>>>> index 6ea98dfcd0278..2b096e5a61cda 100644
>>>> --- a/rust/kernel/time.rs
>>>> +++ b/rust/kernel/time.rs
>>>> @@ -363,6 +363,12 @@ impl Delta {
>>>> /// A span of time equal to zero.
>>>> pub const ZERO: Self = Self { nanos: 0 };
>>>>
>>>> + /// Create a new [`Delta`] from a number of nanoseconds.
>>>> + #[inline]
>>>> + pub const fn from_nanos(nanos: i64) -> Self {
>>>> + Self { nanos }
>>>> + }
>>>> +
>>>> /// Create a new [`Delta`] from a number of microseconds.
>>>> ///
>>>> /// The `micros` can range from -9_223_372_036_854_775 to 9_223_372_036_854_775.
>>>
>>> For consistency with the other methods, perhaps we should also mention
>>> the valid nanos range in the comment?
>>
>> But, please make it a constant instead of an integer literal.
>
> Do you mean making the comment of Delta's from_* methods like the
> following?
>
> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index 6ea98dfcd027..822746e552fb 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -363,9 +363,14 @@ impl Delta {
> /// A span of time equal to zero.
> pub const ZERO: Self = Self { nanos: 0 };
>
> + /// The minimum number of microseconds that can be represented by a [`Delta`].
> + pub const MIN_MICROS: i64 = -9_223_372_036_854_775;
> + /// The maximum number of microseconds that can be represented by a [`Delta`].
> + pub const MAX_MICROS: i64 = 9_223_372_036_854_775;
> +
> /// Create a new [`Delta`] from a number of microseconds.
> ///
> - /// The `micros` can range from -9_223_372_036_854_775 to 9_223_372_036_854_775.
> + /// The `micros` can range from [`Delta::MIN_MICROS`] to [`Delta::MAX_MICROS`].
> /// If `micros` is outside this range, `i64::MIN` is used for negative values,
> /// and `i64::MAX` is used for positive values due to saturation.
> #[inline]
Yes, I would prefer that. The numbers become much more useful like this.
Best regards,
Andreas Hindborg
prev parent reply other threads:[~2025-11-17 12:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 18:42 [PATCH] rust/time: Add Delta::from_nanos() Lyude Paul
2025-11-16 6:38 ` Onur Özkan
2025-11-16 11:06 ` Miguel Ojeda
2025-11-17 10:21 ` Onur Özkan
2025-11-17 1:39 ` FUJITA Tomonori
2025-11-17 11:15 ` Andreas Hindborg
2025-11-17 11:38 ` FUJITA Tomonori
2025-11-17 12:26 ` Andreas Hindborg [this message]
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=87qztw26bf.fsf@metaspace.dk \
--to=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--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=tglx@linutronix.de \
--cc=tmgross@umich.edu \
/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;
as well as URLs for NNTP newsgroup(s).