Skip to content

Add doc for impl From in char_convert #53518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/libcore/char/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ pub unsafe fn from_u32_unchecked(i: u32) -> char {

#[stable(feature = "char_convert", since = "1.13.0")]
impl From<char> for u32 {
/// Converts a [`char`] into a [`u32`].
///
/// # Examples
///
/// ```
/// use std::mem;
///
/// fn main() {
/// let c = 'c';
/// let u = u32::from(c);
/// assert!(4 == mem::size_of_val(&u))
/// }
/// ```
#[inline]
fn from(c: char) -> Self {
c as u32
Expand All @@ -141,6 +154,19 @@ impl From<char> for u32 {
/// C0 and C1 control codes.
#[stable(feature = "char_convert", since = "1.13.0")]
impl From<u8> for char {
/// Converts a [`u8`] into a [`char`].
///
/// # Examples
///
/// ```
/// use std::mem;
///
/// fn main() {
/// let u = 32 as u8;
/// let c = char::from(u);
/// assert!(4 == mem::size_of_val(&c))
/// }
/// ```
#[inline]
fn from(i: u8) -> Self {
i as char
Expand Down