Skip to content

Guidance is necessary on how to interact with rand_core::Error::CUSTOM_START #984

Closed
@nagisa

Description

@nagisa

Currently CUSTOM_START sets the two upper-most bits in the u32, however it is not obvious and documented how many codes are available above this point. For instance, doing something along the lines:

const MY_LIBRARY_BIT: u32 = 1 << 31;
pub const SOME_ERROR: NonZeroU32 = unsafe {
    NonZeroU32::new_unchecked(rand_core::CUSTOM_START + MY_LIBRARY_BIT + 1)
};

will fail to compile because of the addition overflow. If the user were to use bitwise or, the error would become silent, but it isn’t clear whether that’s desirable.

The documentation for CUSTOM_START should document the range of values users can expect to use within the u32.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-docsDocumentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions