lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e93d124b-e2db-4a7d-848c-6d4fb389d780@proton.me>
Date: Wed, 27 Mar 2024 11:18:28 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Boqun Feng <boqun.feng@...il.com>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>, Alice Ryhl <aliceryhl@...gle.com>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Andreas Hindborg <a.hindborg@...sung.com>, John Stultz <jstultz@...gle.com>, Stephen Boyd <sboyd@...nel.org>, Valentin Obst <kernel@...entinobst.de>
Subject: Re: [PATCH 2/5] rust: time: Introduce Duration type

On 26.03.24 18:17, Boqun Feng wrote:
> On Tue, Mar 26, 2024 at 10:11:07AM -0700, Boqun Feng wrote:
> [...]
>>>> +impl Duration {
>>>> +    /// Creates a new duration of `ns` nanoseconds.
>>>> +    pub const fn new(ns: i64) -> Self {
>>>> +        Self { inner: ns }
>>>> +    }
>>>> +
>>>> +    /// Divides the number of nanoseconds by a compile-time constant.
>>>> +    #[inline]
>>>> +    fn divns_constant<const DIV: i64>(self) -> i64 {
>>>> +        self.to_ns() / DIV
>>>> +    }
>>>
>>> I am a bit confused, why is this better than writing
>>> `self.to_ns() / DIV` at the callsite?
>>>
>>
>> Hmm.. you're right, there should be no difference I think. If there is
>> nothing I'm missing from Alice, I will drop this function in the next
>> version.
>>
> 
> On a second thought, I think this prevents accidentally divide a
> non-const value, in other words, if you use this function, you're
> guaranteed the divisor is a constant, and you have the compiler checking
> that for you. So in that sense, I think it makes sense to remain it
> here. Thoughts?

I don't see the value in that. It does not prevent me from just doing
`self.to_ns() / DIV` now. I imagine that 99% of the time users will want
to get milliseconds or microseconds and we should have methods for that
(when we have users). But for the last 1% I don't think we need this
method.

-- 
Cheers,
Benno


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ