from_u32_unchecked: check validity when debug assertions are enabled
This commit is contained in:
parent
4512721156
commit
52ed89ae8c
1 changed files with 2 additions and 2 deletions
|
|
@ -99,7 +99,7 @@ pub fn from_u32(i: u32) -> Option<char> {
|
|||
#[inline]
|
||||
#[stable(feature = "char_from_unchecked", since = "1.5.0")]
|
||||
pub unsafe fn from_u32_unchecked(i: u32) -> char {
|
||||
transmute(i)
|
||||
if cfg!(debug_assertions) { char::from_u32(i).unwrap() } else { transmute(i) }
|
||||
}
|
||||
|
||||
#[stable(feature = "char_convert", since = "1.13.0")]
|
||||
|
|
@ -218,7 +218,7 @@ impl TryFrom<u32> for char {
|
|||
Err(CharTryFromError(()))
|
||||
} else {
|
||||
// SAFETY: checked that it's a legal unicode value
|
||||
Ok(unsafe { from_u32_unchecked(i) })
|
||||
Ok(unsafe { transmute(i) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue