On Thu Dec 3, 2026 at 9:09 PM JST, Alexandre Courbot wrote:
> It is useful to be able to build keys as constants, which the `From`
> implementation does not allow. Add a const `new` constructor and use it
> where relevant.
>
> Signed-off-by: Alexandre Courbot <[email protected]>
> ---
>  drivers/gpu/nova-core/gsp/nvkv.rs | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/gsp/nvkv.rs 
> b/drivers/gpu/nova-core/gsp/nvkv.rs
> index f81a9e60d89c..20015b5b0509 100644
> --- a/drivers/gpu/nova-core/gsp/nvkv.rs
> +++ b/drivers/gpu/nova-core/gsp/nvkv.rs
> @@ -50,17 +50,22 @@ impl<T, const KEY_ID: KeyId, As> Key<T, KEY_ID, As> {
>      /// The maximum size in bytes we allow to materialize on the stack while
>      /// encoding or decoding a [`Key`]. This is checked at compile time.
>      const MAX_STACK_SIZE: usize = 32;
> +
> +    /// Create a new [`Key`] from `value`.
> +    pub(crate) const fn new(value: T) -> Self {
> +        Self(value, PhantomData)
> +    }
>  }
>  
>  impl<T, const KEY_ID: KeyId, As> From<T> for Key<T, KEY_ID, As> {
>      fn from(value: T) -> Self {
> -        Self(value, PhantomData)
> +        Self::new(value)
>      }
>  }
>  
>  impl<'a, T, const KEY_ID: KeyId, As, const N: usize> From<&'a [T; N]> for 
> Key<&'a [T], KEY_ID, As> {
>      fn from(value: &'a [T; N]) -> Self {
> -        Self(&value[..], PhantomData)
> +        Self::new(&value[..])
>      }
>  }
>  

optional nit: Also switch the Default impl over?

Reviewed-by: Eliot Courtney <[email protected]>

Reply via email to