You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mem::Alignment: Naming the -> NonZero<usize> method. #154237
Brought up in #154004 (comment): Should the method on Alignment that gives a NonNull<usize> be spelled as_nonzero, as_nonzero_usize, as_non_zero_usize, get, or what?
Nominating for libs-api thoughts so someone can make a PR for whatever the answer is.
Alternatively, this could be more like NonZero itself and just have new/get, since .get().get() would exist to go Alignment -> NonZero<usize> -> usize. Going safely & infallibly that way is important. Going the other way of course is fallible or unsafe so the types involved are in some sense less important. new_unchecked's precondition is is_power_of_two whether it's on usize or NonZero<usize>, though on the latter that's slightly more efficient of a check (for new), though I suspect the combination optimizes together nicely either way.
changed the title [-]`mem::Alignment`: Naming the `-> NonNull<usize>` method.[/-][+]`mem::Alignment`: Naming the `-> NonZero<usize>` method.[/+]on Mar 23, 2026
We discussed this in today's @rust-lang/libs-api meeting and we agreed on naming it as_nonzero_usize - with the caveat that this isn't necessarily precedent-setting that as_* methods should specify the return type in the name. Thanks ^^
Activity
mem::Alignmenttype #102070[-]Naming the `-> NonNull<usize>` method.[/-][+]`mem::Alignment`: Naming the `-> NonNull<usize>` method.[/+]clarfonthey commentedon Mar 23, 2026
Don't feel like deduping/rewarding ATM so here's my analysis of non_zero vs. nonzero I posted: #154004 (comment)
(feel free to incorporate into issue description yourself)
lqd commentedon Mar 23, 2026
(There are a couple mentions of
NonNull<usize>instead ofNonZero<usize>)[-]`mem::Alignment`: Naming the `-> NonNull<usize>` method.[/-][+]`mem::Alignment`: Naming the `-> NonZero<usize>` method.[/+]nia-e commentedon Mar 24, 2026
We discussed this in today's @rust-lang/libs-api meeting and we agreed on naming it
as_nonzero_usize- with the caveat that this isn't necessarily precedent-setting thatas_*methods should specify the return type in the name. Thanks ^^@rustbot label -I-libs-api-nominated
clarfonthey commentedon Mar 24, 2026
So, I guess we can just close this as resolved since that's what the current PR has.
Rollup merge of rust-lang#157226 - theemathas:stab-box-vec-non-null, …
Unrolled build for #157226