Line-breaks are allowed in string literals. A line-break is either a newline (U+000A ) or a pair of carriage return and newline (U+000D , U+000A ). Both byte sequences are normally translated to U+000A , but as a special exception, when an unescaped U+005C character (\ ) occurs immediately before a line break, then the line break character(s), and all immediately following `` (U+0020 ), \t (U+0009 ), \n (U+000A ) and \r (U+0000D ) characters are ignored.
In a hand-wavy sense Rust treats an EOL backslash as you saying "I want to continue this on next line, but I also don't want to screw up my indentation.".
There’s no way to tell it that, however you could put the space(s) between one and two at the end of the previous line instead
fn main() {
let s: &str="\
one \
two\
three";
println!("{}",s);
}
Of course, for the concrete example at hand, it’s better written "one twothree" directly and in a single line anyways. If you shared some actual (practical) use-case you’re using the \+linebreak syntax for, maybe we could debate alternatives and help figure out the best (or least-ugly) way to express the string in Rust.
Which is a useful tool in general, but I don’t think it applies here in particular, because the request was to not keep the line breaks in the actual string data created.
With multiple line text blocks, I don't like putting leading whitespace at the end of my source lines, as it's hard to get the indentation correct with ragged lines. So instead I do things like this:
let s = "\
\x20 one\n\
\x20 two\n\
\x20 three\n\
";
(Though it'd be nicer if "\ " could be used instead of "\x20".)
Maybe even nicer than an escape for spaces would be something like \& in Haskell that expands to nothing. Their main use-case is different, since they have variable-length non-delimited numeric character code escapes, disambiguating e. g. \137 (one character) from \13\&7 (two characters, \13 and 7) is occasionally necessary.
By the way, note that I wasn't suggesting to put leading spaces at the end of the line, the original post was about a string without line breaks and thus without a real difference between apparently "leading" or apparently "trailing" whitespace.
Two dimensional byte arrays could work as well - better in a way since all the characters are ascii. However - can't be formatted with concat! and I prefer to keep the board 1-dimensional - it is simpler because the 'squares' are enumerable and hence only need one index; though for display purposes they still need to be translated to x,y...
Her is a link to the program - pacman. It is a port from an older C version of the game.