Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nagisa opened this issue Jun 6, 2020 · 2 comments
Closed
Labels
C-docs Documentation

Comments

@nagisa
Copy link
Contributor

nagisa commented Jun 6, 2020

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.

@dhardy
Copy link
Member

dhardy commented Jun 8, 2020

True. We should probably also document the value of CUSTOM_START, since it is not expected to change.

@newpavlov @josephlr

(Affects doc in rand_core/src/error.rs and getrandom/src/error.rs.)

@dhardy
Copy link
Member

dhardy commented Nov 2, 2020

The above PR fixes this (for Rand crates at least).

@dhardy dhardy closed this as completed Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-docs Documentation
Projects
None yet
Development

No branches or pull requests

2 participants