-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[Design] confusing target_pointer_width = "64"
usize convertion design
#138218
Comments
target_pointer_width = "64"
usize convertiontarget_pointer_width = "64"
usize convertion
target_pointer_width = "64"
usize convertiontarget_pointer_width = "64"
usize convertion design
This is deliberate, we don't want people writing unportable code by accident. This is why trait implementations are not made available conditionally. |
Why is unportable? Are there real world #[cfg(target_pointer_width = "64")]
{
// let _ = usize::try_from(42u64).unwrap();
// let _ = usize::try_from(42u32).unwrap();
// let _ = usize::from(42u16);
let _ = usize::from(42u64);
let _ = usize::from(42u32);
let _ = usize::from(42u16);
} |
@loynoir If there was an implementation of That said, I've never fully agreed with Rust's choice here - if like most users you never expect to target 16-bit, then you end up writing A possible middle ground would be to have |
Title
confusing
target_pointer_width = "64"
usize convertion designActual
Expected
When under target_pointer_width 64, should always success, and try is not necessary.
Related
https://github.com/rust-lang/rust/blob/master/library/core/src/convert/num.rs
The text was updated successfully, but these errors were encountered: