Reputation: 24547
How do you convert an ascii string literal (say, "123 458") into a &[u8]
slice in rust? Rust has 6? 7? string types, and there is almost no uniformity in what you call to convert between them.
I'm expecting it to be something along the lines of:
let array:&[u8] = Ascii("123 456").into_bytes().as_slice().givemetheeffingbufferalready() as &[u8];
Please take it on faith that I actually need to do this; I am writing test cases for some file parser code.
Upvotes: 23
Views: 15363
Reputation: 24547
After much digging through other related answers, and getting corrected by the nightly version of the compiler, I found out it is trivial; you just add a 'b' to your literal:
let array:&[u8] = b"123 456";
Upvotes: 36