File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,48 @@ impl From<char> for u32 {
112
112
}
113
113
}
114
114
115
+ #[ stable( feature = "more_char_conversions" , since = "1.50.0" ) ]
116
+ impl From < char > for u64 {
117
+ /// Converts a [`char`] into a [`u64`].
118
+ ///
119
+ /// # Examples
120
+ ///
121
+ /// ```
122
+ /// use std::mem;
123
+ ///
124
+ /// let c = '👤';
125
+ /// let u = u64::from(c);
126
+ /// assert!(8 == mem::size_of_val(&u))
127
+ /// ```
128
+ #[ inline]
129
+ fn from ( c : char ) -> Self {
130
+ // The char is casted to the value of the code point, then zero-extended to 64 bit.
131
+ // See [https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics]
132
+ c as u64
133
+ }
134
+ }
135
+
136
+ #[ stable( feature = "more_char_conversions" , since = "1.50.0" ) ]
137
+ impl From < char > for u128 {
138
+ /// Converts a [`char`] into a [`u128`].
139
+ ///
140
+ /// # Examples
141
+ ///
142
+ /// ```
143
+ /// use std::mem;
144
+ ///
145
+ /// let c = '⚙';
146
+ /// let u = u128::from(c);
147
+ /// assert!(16 == mem::size_of_val(&u))
148
+ /// ```
149
+ #[ inline]
150
+ fn from ( c : char ) -> Self {
151
+ // The char is casted to the value of the code point, then zero-extended to 128 bit.
152
+ // See [https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics]
153
+ c as u128
154
+ }
155
+ }
156
+
115
157
/// Maps a byte in 0x00..=0xFF to a `char` whose code point has the same value, in U+0000..=U+00FF.
116
158
///
117
159
/// Unicode is designed such that this effectively decodes bytes
You can’t perform that action at this time.
0 commit comments