Skip to content

Commit 992e220

Browse files
committed
Add examples for doc
1 parent 1acec4c commit 992e220

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Diff for: src/libcore/char/convert.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,17 @@ pub unsafe fn from_u32_unchecked(i: u32) -> char {
117117
impl From<char> for u32 {
118118
/// Converts a [`char`] into a [`u32`].
119119
///
120-
/// [`char`]: primitive.char.html
121-
/// [`u32`]: primitive.u32.html
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+
/// ```
122131
#[inline]
123132
fn from(c: char) -> Self {
124133
c as u32
@@ -147,8 +156,17 @@ impl From<char> for u32 {
147156
impl From<u8> for char {
148157
/// Converts a [`u8`] into a [`char`].
149158
///
150-
/// [`u8`]: primitive.u8.html
151-
/// [`char`]: primitive.char.html
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+
/// ```
152170
#[inline]
153171
fn from(i: u8) -> Self {
154172
i as char

0 commit comments

Comments
 (0)