error invalid-escape
Недопустимая escape-последовательность.
What it means#
Inside ordinary and character literals only these escapes exist: \n \r \t \\ \" \' \0 \xHH \u{H...} (§1.5). Any other backslash sequence, a \x without two hex digits, or a \u{...} that is not a Unicode scalar value is rejected.
Example#
fn main() {
let path = "C:\path\file.txt" // <- invalid-escape (\p and \f are not escapes)
}error
invalid-escape
How to fix#
fn main() {
let path = r"C:\path\file.txt"
}Double the backslash (\\) or use a raw string r"...", in which backslashes are literal. The contents of prefixed literals such as re"\d+" are raw by definition (decision D-003).