mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
5c0f5b69c2
Implement From<char> for u64 and u128. With this PR you can write ``` let u = u64::from('👤'); let u = u128::from('👤'); ``` Previously, you could already write `as` conversions ([Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cee18febe28e69024357d099f07ca081)): ``` // Lossless conversions dbg!('👤' as u32); // Prints 128100 dbg!('👤' as u64); // Prints 128100 dbg!('👤' as u128); // Prints 128100 // truncates, thus no `From` impls. dbg!('👤' as u8); // Prints 100 dbg!('👤' as u16); // Prints 62564 // These `From` impls already exist. dbg!(u32::from('👤')); // Prints 128100 dbg!(u64::from(u32::from('👤'))); // Prints 128100 ``` The idea is from ``@gendx`` who opened [this Internals thread](https://internals.rust-lang.org/t/implement-from-char-for-u64/13454), and ``@withoutboats`` responded that someone should open a PR for it. Some people mentioned `From<char>` impls for `f32` and `f64`, but that doesn't seem correct to me, so I didn't include them here. I don't know what the feature should be named. Must it be registered somewhere, like unstable features? r? ``@withoutboats`` |
||
---|---|---|
.. | ||
benches | ||
src | ||
tests | ||
Cargo.toml |