Re: [PATCH] rust/time: Add Delta::from_nanos()
From: Andreas Hindborg
Date: Thu Feb 19 2026 - 05:51:01 EST
FUJITA Tomonori <fujita.tomonori@xxxxxxxxx> writes:
> On Fri, 14 Nov 2025 13:42:06 -0500
> Lyude Paul <lyude@xxxxxxxxxx> wrote:
>
>> Since rvkms is going to need to create its own Delta instances, and we
>> already have functions for creating Delta with every other unit of time.
>>
>> Signed-off-by: Lyude Paul <lyude@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..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?
On second thought, since valid range is any valid `i64` value, I don't
think this matters.
Best regards,
Andreas Hindborg