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

navajo: Add 16-bit and 128-bit support in rand::Rng::usize #51

Open
chanced opened this issue Apr 18, 2023 · 0 comments
Open

navajo: Add 16-bit and 128-bit support in rand::Rng::usize #51

chanced opened this issue Apr 18, 2023 · 0 comments

Comments

@chanced
Copy link
Owner

chanced commented Apr 18, 2023

    pub fn usize(&self) -> Result<usize, RandomError> {
        // future-proofing
        #[cfg(target_pointer_width = "128")]
        {
            let mut dst = [0; 16];
            fill(&mut dst)?;
            Ok(usize::from_ne_bytes(dst))
        }
        #[cfg(target_pointer_width = "64")]
        {
            let mut dst = [0; 8];
            fill(&mut dst)?;
            Ok(usize::from_ne_bytes(dst))
        }
        #[cfg(target_pointer_width = "32")]
        {
            let mut dst = [0; 4];
            fill(&mut dst)?;
            Ok(usize::from_ne_bytes(dst))
        }
        #[cfg(target_pointer_width = "16")]
        {
            let mut dst = [0; 2];
            fill(&mut dst)?;
            Ok(usize::from_ne_bytes(dst))
        }
        #[cfg(all(
            not(target_pointer_width = "128"),
            not(target_pointer_width = "64"),
            not(target_pointer_width = "32"),
            not(target_pointer_width = "16"),
        ))]
        {
            compile_error!("Unsupported target_pointer_width")
        }
    }
@chanced chanced changed the title Add 16-bit and 128-bit support in rand::Rng::usize navajo: Add 16-bit and 128-bit support in rand::Rng::usize Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant