-
I know that Rust has a char literal notation: char - Rust
-
I want to create u8 literals (in particular, chars 0 -> 127). Is there a better way than
let x = "x";
let t = x.as_bytes()[0];
I know that Rust has a char literal notation: char - Rust
I want to create u8 literals (in particular, chars 0 -> 127). Is there a better way than
let x = "x";
let t = x.as_bytes()[0];
let t = b'x';
As @scottmcm mentioned, there is the b'c'
notation, or the b"string"
notation for strings. This will actually turn them into a &'static u8
(Or u8
for char notation). Also note that you can only use standard ASCII characters. This won't work for chars with an accent for example; (Playground)