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

Feature request: new_with_u32 #44

Closed
danlehmann opened this issue Jul 12, 2024 · 0 comments · Fixed by #47
Closed

Feature request: new_with_u32 #44

danlehmann opened this issue Jul 12, 2024 · 0 comments · Fixed by #47

Comments

@danlehmann
Copy link
Owner

danlehmann commented Jul 12, 2024

In our codebase we see this pattern quite a lot:

let x: u32;
u7::new(x as u8);

This is problematic as the u8-to-u7 is range-checked, but the u32-to-u8 is not. This can be addressed by u7::new(x.try_into().unwrap()), but that's a) clunky and b) not const safe.

A good fix would be to provide new_from_u32 (or from_u32?) and try_new_from_u32/try_from_u32 (as well as other built-in types).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant