[PATCH v2 17/21] rust: num: Add an upward alignment helper for usize
Timur Tabi
ttabi at nvidia.com
Thu May 1 15:19:35 UTC 2025
On Thu, 2025-05-01 at 21:58 +0900, Alexandre Courbot wrote:
> +impl UsizeAlign for usize {
> + fn align_up(mut self, align: usize) -> usize {
> + self = (self + align - 1) & !(align - 1);
> + self
> + }
> +}
> +
> +/// Aligns `val` upwards to the nearest multiple of `align`.
> +pub const fn usize_align_up(val: usize, align: usize) -> usize {
> + (val + align - 1) & !(align - 1)
> +}
Why not have usize_align_up() just return "val.align_up(align)"?
But why why two versions at all? Is there any context where you could use one
and not the other?
More information about the dri-devel
mailing list