rust: num: make Bounded::get const

There is a need to access the inner value of a `Bounded` in const
context, notably for bitfields and registers. Remove the invariant check
of `Bounded::get`, which allows us to make it const.

Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://patch.msgid.link/20260314-register-v9-4-86805b2f7e9d@nvidia.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Alexandre Courbot 2026-03-14 10:06:14 +09:00 committed by Danilo Krummrich
parent 164f8634bf
commit 7836ec76ec

View File

@ -379,6 +379,9 @@ pub fn from_expr(expr: T) -> Self {
/// Returns the wrapped value as the backing type.
///
/// This is similar to the [`Deref`] implementation, but doesn't enforce the size invariant of
/// the [`Bounded`], which might produce slightly less optimal code.
///
/// # Examples
///
/// ```
@ -387,8 +390,8 @@ pub fn from_expr(expr: T) -> Self {
/// let v = Bounded::<u32, 4>::new::<7>();
/// assert_eq!(v.get(), 7u32);
/// ```
pub fn get(self) -> T {
*self.deref()
pub const fn get(self) -> T {
self.0
}
/// Increases the number of bits usable for `self`.