From: Andreas Hindborg <a.hindborg@kernel.org>
To: "FUJITA Tomonori" <fujita.tomonori@gmail.com>
Cc: <alex.gaynor@gmail.com>, <ojeda@kernel.org>,
<aliceryhl@google.com>, <anna-maria@linutronix.de>,
<bjorn3_gh@protonmail.com>, <boqun.feng@gmail.com>,
<dakr@kernel.org>, <frederic@kernel.org>, <gary@garyguo.net>,
<jstultz@google.com>, <linux-kernel@vger.kernel.org>,
<lossin@kernel.org>, <lyude@redhat.com>,
<rust-for-linux@vger.kernel.org>, <sboyd@kernel.org>,
<tglx@linutronix.de>, <tmgross@umich.edu>
Subject: Re: [PATCH v1] rust: time: Add examples with doctest for Delta
Date: Wed, 02 Jul 2025 10:36:19 +0200 [thread overview]
Message-ID: <874ivvvvjw.fsf@kernel.org> (raw)
In-Reply-To: <20250701001809.496389-1-fujita.tomonori@gmail.com> (FUJITA Tomonori's message of "Tue, 01 Jul 2025 09:18:09 +0900")
"FUJITA Tomonori" <fujita.tomonori@gmail.com> writes:
> Add examples with doctest for Delta methods and associated
> functions. These examples explicitly test overflow and saturation
> behavior.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
> rust/kernel/time.rs | 67 +++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 67 insertions(+)
>
> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index 64c8dcf548d6..c6322275115a 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -228,11 +228,34 @@ 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.
> + ///
> + /// The `nanos` can range from [`i64::MIN`] to [`i64::MAX`].
> + #[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.
> /// If `micros` is outside this range, `i64::MIN` is used for negative values,
> /// and `i64::MAX` is used for positive values due to saturation.
> + ///
> + /// # Examples
> + ///
> + /// ```
> + /// let delta = kernel::time::Delta::from_micros(5);
> + /// assert_eq!(delta.as_nanos(), 5_000);
> + /// let delta = kernel::time::Delta::from_micros(9_223_372_036_854_775);
> + /// assert_eq!(delta.as_nanos(), 9_223_372_036_854_775_000);
> + /// let delta = kernel::time::Delta::from_micros(9_223_372_036_854_776);
> + /// assert_eq!(delta.as_nanos(), i64::MAX);
> + /// let delta = kernel::time::Delta::from_micros(-9_223_372_036_854_775);
> + /// assert_eq!(delta.as_nanos(), -9_223_372_036_854_775_000);
> + /// let delta = kernel::time::Delta::from_micros(-9_223_372_036_854_776);
> + /// assert_eq!(delta.as_nanos(), i64::MIN);
> + /// ```
I think this kind of test would be better suited for the new `#[test]`
macro. Would you agree?
Best regards,
Andreas Hindborg
next prev parent reply other threads:[~2025-07-02 8:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <kyrCsGDYN5QdXPkUe4OxMxU2UzHfJ-vH5z643gA-_KFJIaew0duyMXU0yfTrGN5ZCNaecP8Yu2kIXKXMoWS2lA==@protonmail.internalid>
2025-07-01 0:18 ` [PATCH v1] rust: time: Add examples with doctest for Delta FUJITA Tomonori
2025-07-02 8:36 ` Andreas Hindborg [this message]
2025-07-02 9:09 ` FUJITA Tomonori
2025-07-02 12:34 ` Miguel Ojeda
2025-07-02 12:22 ` Miguel Ojeda
2025-07-04 0:36 ` FUJITA Tomonori
2025-07-04 7:28 ` Andreas Hindborg
2025-07-04 7:38 ` Miguel Ojeda
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=874ivvvvjw.fsf@kernel.org \
--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).