expression

Byte string literals

A byte string literal is a borrowed fixed-size byte array, not &str. Non-ASCII bytes can be represented with byte escapes. Expected stdout (not executed): [73, 68, 255] true Common mistake: Writing unescaped Persian characters directly inside a byte string literal.

Formal Syntax & Structure

rust syntaxrust
b"ASCII"

Working Example

Example Snippetrust
fn main() {    let data = b"ID\xFF";    println!("{:?}", data);    println!("{}", std::str::from_utf8(data).is_err());}
Rust Reference