Skip to content

Commit 0bcced9

Browse files
committed
Remove unnecessary transmute and expand some unsafe blocks
1 parent 984cc28 commit 0bcced9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/ascii.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ impl Ascii {
194194
/// ```
195195
#[inline]
196196
pub fn from(ch: char) -> Result<Ascii, ()> {
197-
if ch as u32 <= 0x7F {
198-
return Ok(unsafe{ ch.to_ascii_nocheck() });
199-
}
197+
unsafe{if ch as u32 <= 0x7F {
198+
return Ok(ch.to_ascii_nocheck());
199+
}}
200200
Err(())
201201
}
202202

@@ -215,16 +215,16 @@ impl Ascii {
215215
/// ```
216216
#[inline]
217217
pub fn from_byte(ch: u8) -> Result<Ascii, ()> {
218-
if ch <= 0x7F {
219-
return Ok(unsafe{ ch.to_ascii_nocheck() });
220-
}
218+
unsafe{if ch <= 0x7F {
219+
return Ok(ch.to_ascii_nocheck());
220+
}}
221221
Err(())
222222
}
223223

224224
/// Converts an ascii character into a `u8`.
225225
#[inline]
226226
pub fn as_byte(&self) -> u8 {
227-
unsafe{ transmute(*self) }
227+
*self as u8
228228
}
229229

230230
/// Converts an ascii character into a `char`.

0 commit comments

Comments
 (0)