Byte literal not escaped when pushed onto String



The escaping backslash in the byte literal for apostrophe b’\’’ is not removed when used in a String.


O’Brien becomes O\'Brien

Here are some code snippets to show it…

let apos = vec![39];

prints out “\’”

let apos: char = '\'';
let mut s = String::new();

prints out “\’”

let apos: char = '\'';
print!("byte literal is {:?} and u8 is {:?}",b'\'', apos as u8);

prints out byte literal is 39 and u8 is 39


How can remove the escaping backslash when pushing the char onto a String, so that O’Brien remains O’Brien?


Try using the Display output (ie {}) format instead of Debug (ie {:?})


thank you very much. You are correct. I was using Debug in my tests so they kept failing. Display works.