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: <879031CB-A9A6-486A-8E01-E557ABB01F41@collabora.com>
Date: Fri, 6 Feb 2026 15:28:08 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Alexandre Courbot <acourbot@...dia.com>
Cc: Danilo Krummrich <dakr@...nel.org>,
 Alice Ryhl <aliceryhl@...gle.com>,
 Miguel Ojeda <ojeda@...nel.org>,
 Boqun Feng <boqun.feng@...il.com>,
 Gary Guo <gary@...yguo.net>,
 Björn Roy Baron <bjorn3_gh@...tonmail.com>,
 Benno Lossin <lossin@...nel.org>,
 Andreas Hindborg <a.hindborg@...nel.org>,
 Trevor Gross <tmgross@...ch.edu>,
 Yury Norov <yury.norov@...il.com>,
 John Hubbard <jhubbard@...dia.com>,
 Alistair Popple <apopple@...dia.com>,
 Joel Fernandes <joelagnelf@...dia.com>,
 Timur Tabi <ttabi@...dia.com>,
 Edwin Peer <epeer@...dia.com>,
 Eliot Courtney <ecourtney@...dia.com>,
 Dirk Behme <dirk.behme@...bosch.com>,
 Steven Price <steven.price@....com>,
 rust-for-linux@...r.kernel.org,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5 3/7] rust: num: add `as_bool` method to `Bounded<_, 1>`



> On 29 Jan 2026, at 10:32, Alexandre Courbot <acourbot@...dia.com> wrote:
> 
> Single-bit numbers are typically treated as booleans. There is an
> `Into<bool>` implementation for those, but invoking it from contexts
> that lack type expectations is not always convenient.
> 
> Add an `as_bool` method as a simpler shortcut.
> 
> Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> Reviewed-by: Gary Guo <gary@...yguo.net>
> Tested-by: Dirk Behme <dirk.behme@...bosch.com>
> Acked-by: Miguel Ojeda <ojeda@...nel.org>
> Signed-off-by: Alexandre Courbot <acourbot@...dia.com>
> ---
> rust/kernel/num/bounded.rs | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
> 
> diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs
> index 4b929762d5c2..b41ca6df1525 100644
> --- a/rust/kernel/num/bounded.rs
> +++ b/rust/kernel/num/bounded.rs
> @@ -1098,3 +1098,24 @@ fn from(value: bool) -> Self {
>         Self::__new(T::from(value))
>     }
> }
> +
> +impl<T> Bounded<T, 1>
> +where
> +    T: Integer + Zeroable,
> +{
> +    /// Returns the value of this [`Bounded`] as a [`bool`].
> +    ///
> +    /// This is a shorter way of writing `bool::from(self)`.
> +    ///
> +    /// # Examples
> +    ///
> +    /// ```
> +    /// use kernel::num::Bounded;
> +    ///
> +    /// assert_eq!(Bounded::<u8, 1>::new::<0>().as_bool(), false);
> +    /// assert_eq!(Bounded::<u8, 1>::new::<1>().as_bool(), true);
> +    /// ```
> +    pub fn as_bool(self) -> bool {
> +        self.into()
> +    }
> +}
> 
> -- 
> 2.52.0
> 

I wonder whether this should be into_bool() instead? as_foo() usually goes from &self to &Foo.

In any case:

Reviewed-by: Daniel Almeida <daniel.almeida@...labora.com>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ