diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-01-10 16:55:53 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-10 16:55:53 +0900 |
| commit | 5c0f5b69c2b11a16f34ff25da69be831336f3596 (patch) | |
| tree | c79198a04b0639b0453a377e8269d74e5b50c1f2 /src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs | |
| parent | 7cf205610e1310897f43b35713a42459e8b40c64 (diff) | |
| parent | e8cb72c503ff02144876578e38f4782414750776 (diff) | |
| download | rust-5c0f5b69c2b11a16f34ff25da69be831336f3596.tar.gz rust-5c0f5b69c2b11a16f34ff25da69be831336f3596.zip | |
Rollup merge of #79502 - Julian-Wollersberger:from_char_for_u64, r=withoutboats
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``
Diffstat (limited to 'src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs')
0 files changed, 0 insertions, 0 deletions
