Skip to content

impl Div<NonZeroXxx> and Rem<NonZeroXxx> for xxx #3033

Description

@mqudsi

One obvious optimization that is possible with NonZeroXxx aside from simply elision of extra storage for Option<NonZeroXxx> is that it enables safe unchecked code that skips divide by zero checking.

It would be nice if, e.g., Rem<NonZeroUsize> were implemented for usize such that this would be a valid operation:

fn fast_and_safe(dividend: usize, divisor: NonZeroUsize) -> usize {
    dividend % divisor
}

This would be guaranteed panic free and there would be no need to generate the code that handles the case where divisor is zero.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions