summaryrefslogtreecommitdiff
path: root/drivers/gpu/nova-core/sbuffer.rs
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2025-11-10 22:34:11 +0900
committerAlexandre Courbot <acourbot@nvidia.com>2025-11-14 20:25:15 +0900
commit89605daa1ee0de634d7f2ee6370363cfaa8c9499 (patch)
tree812fc7c779d3e59cde3b495d10db39206904395c /drivers/gpu/nova-core/sbuffer.rs
parent1101c442410cd57af848c30804e985aab9e0e569 (diff)
gpu: nova-core: num: add functions to safely convert a const value to a smaller type
There are times where we need to store a constant value defined as a larger type (e.g. through a binding) into a smaller type, knowing that the value will fit. Rust, unfortunately, only provides us with the `as` operator for that purpose, the use of which is discouraged as it silently strips data. Extend the `num` module with functions allowing to perform the conversion infallibly, at compile time. Example: const FOO_VALUE: u32 = 1; // `FOO_VALUE` fits into a `u8`, so the conversion is valid. let foo = num::u32_to_u8::<{ FOO_VALUE }>(); We are going to use this feature extensively in Nova. Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com> [acourbot@nvidia.com: fix mistake in example pointed out by Mikko.] Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Message-ID: <20251110-gsp_boot-v9-3-8ae4058e3c0e@nvidia.com>
Diffstat (limited to 'drivers/gpu/nova-core/sbuffer.rs')
0 files changed, 0 insertions, 0 deletions