mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
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:
parent
164f8634bf
commit
7836ec76ec
|
|
@ -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`.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user