[PATCH v5 4/7] rust: num: add `into_inner` method to `Bounded`

Alexandre Courbot posted 7 patches 1 week, 3 days ago
[PATCH v5 4/7] rust: num: add `into_inner` method to `Bounded`
Posted by Alexandre Courbot 1 week, 3 days ago
This is useful to access the inner value in const contexts.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 rust/kernel/num/bounded.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs
index b41ca6df1525..850827033f67 100644
--- a/rust/kernel/num/bounded.rs
+++ b/rust/kernel/num/bounded.rs
@@ -388,6 +388,22 @@ pub fn get(self) -> T {
         *self.deref()
     }
 
+    /// Returns the wrapped value as the backing type.
+    ///
+    /// This is a const-friendly variant of [`Self::get`] that can be used in const contexts.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use kernel::num::Bounded;
+    ///
+    /// const V: u32 = Bounded::<u32, 4>::new::<7>().into_inner();
+    /// assert_eq!(V, 7u32);
+    /// ```
+    pub const fn into_inner(self) -> T {
+        self.0
+    }
+
     /// Increases the number of bits usable for `self`.
     ///
     /// This operation cannot fail.

-- 
2.52.0
Re: [PATCH v5 4/7] rust: num: add `into_inner` method to `Bounded`
Posted by Daniel Almeida 2 days, 6 hours ago

> On 29 Jan 2026, at 10:32, Alexandre Courbot <acourbot@nvidia.com> wrote:
> 
> This is useful to access the inner value in const contexts.
> 
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
> rust/kernel/num/bounded.rs | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
> 
> diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs
> index b41ca6df1525..850827033f67 100644
> --- a/rust/kernel/num/bounded.rs
> +++ b/rust/kernel/num/bounded.rs
> @@ -388,6 +388,22 @@ pub fn get(self) -> T {
>         *self.deref()
>     }
> 
> +    /// Returns the wrapped value as the backing type.
> +    ///
> +    /// This is a const-friendly variant of [`Self::get`] that can be used in const contexts.
> +    ///
> +    /// # Examples
> +    ///
> +    /// ```
> +    /// use kernel::num::Bounded;
> +    ///
> +    /// const V: u32 = Bounded::<u32, 4>::new::<7>().into_inner();
> +    /// assert_eq!(V, 7u32);
> +    /// ```
> +    pub const fn into_inner(self) -> T {
> +        self.0
> +    }
> +
>     /// Increases the number of bits usable for `self`.
>     ///
>     /// This operation cannot fail.
> 
> -- 
> 2.52.0
> 
> 

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