Skip to content

Return Option instead of panicking inside new #21

@Lakelezz

Description

@Lakelezz

Hello!

I was looking at the crate and read that new will panic if the value cannot be represented by the type.
Understandably, uX's types require the new-function to be constructed as they are not integer primitives thus u31 cannot utilise the same construction as e.g. u32.

Nonetheless, when we look at e.g. NonZeroU32's new (and the other NonZero-types) - which is a custom integer too - it returns Option instead of panicking when the conditions are not met. This might an interesting guideline to follow.

Hence my question: Might changing uX's new-functions to return Option be of interest?
Mirroring new_unchecked could be feasible too but the std does not run assertions in them.

If wanted, I would be willing to perform this change : )

Thanks for your time!

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