mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Implement TryFrom<char> for u8
Previously suggested in https://github.com/rust-lang/rfcs/issues/2854. It makes sense to have this since `char` implements `From<u8>`. Likewise `u32`, `u64`, and `u128` (since #79502) implement `From<char>`.
This commit is contained in:
committed by
Ian Douglas Scott
parent
e012a191d7
commit
a02639dc09
@@ -544,3 +544,15 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
/// The error type returned when a checked char conversion fails.
|
||||
#[stable(feature = "u8_from_char", since = "1.59.0")]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct TryFromCharError(pub(crate) ());
|
||||
|
||||
#[stable(feature = "u8_from_char", since = "1.59.0")]
|
||||
impl fmt::Display for TryFromCharError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
"unicode code point out of range".fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user