Re: [PATCH v5 21/38] rust: ptr: add const_align_up() and enable inline_const feature
From: John Hubbard
Date: Wed Mar 04 2026 - 14:25:10 EST
On 3/4/26 11:04 AM, Gary Guo wrote:
> On Wed Mar 4, 2026 at 6:53 PM GMT, John Hubbard wrote:
>> On 3/4/26 3:18 AM, Gary Guo wrote:
>>> On Wed Mar 4, 2026 at 3:47 AM GMT, John Hubbard wrote:
>> ...
>> +#[inline(always)]
>> +pub const fn const_align_up<const ALIGN: usize>(value: usize) -> Option<usize> {
>> + const { assert!(ALIGN.is_power_of_two(), "ALIGN must be a power of two") };
>> + match value.checked_add(ALIGN - 1) {
>> + Some(v) => Some(v & !(ALIGN - 1)),
>> + None => None,
>> + }
>> +}
>
> I think your signature should probably just be
>
> pub const fn const_align_up(value: usize, align: Alignment) -> Option<usize> {
> ...
> }
>
OK yes that's a bit nicer. I've done that for v6, thanks!
thanks,
--
John Hubbard