Skip to content

Commit 707c979

Browse files
authored
Rollup merge of rust-lang#53518 - phungleson:fix-impl-from-for-convert, r=frewsxcv
Add doc for impl From in char_convert As part of issue rust-lang#51430 (cc @skade). The impl is very simple, let me know if we need to go into any details.
2 parents 31789a6 + 992e220 commit 707c979

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/libcore/char/convert.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ pub unsafe fn from_u32_unchecked(i: u32) -> char {
115115

116116
#[stable(feature = "char_convert", since = "1.13.0")]
117117
impl From<char> for u32 {
118+
/// Converts a [`char`] into a [`u32`].
119+
///
120+
/// # Examples
121+
///
122+
/// ```
123+
/// use std::mem;
124+
///
125+
/// fn main() {
126+
/// let c = 'c';
127+
/// let u = u32::from(c);
128+
/// assert!(4 == mem::size_of_val(&u))
129+
/// }
130+
/// ```
118131
#[inline]
119132
fn from(c: char) -> Self {
120133
c as u32
@@ -141,6 +154,19 @@ impl From<char> for u32 {
141154
/// C0 and C1 control codes.
142155
#[stable(feature = "char_convert", since = "1.13.0")]
143156
impl From<u8> for char {
157+
/// Converts a [`u8`] into a [`char`].
158+
///
159+
/// # Examples
160+
///
161+
/// ```
162+
/// use std::mem;
163+
///
164+
/// fn main() {
165+
/// let u = 32 as u8;
166+
/// let c = char::from(u);
167+
/// assert!(4 == mem::size_of_val(&c))
168+
/// }
169+
/// ```
144170
#[inline]
145171
fn from(i: u8) -> Self {
146172
i as char

0 commit comments

Comments
 (0)