Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rust backslash in '' not terminated

in my rust program, I need to declare a mutable variable called start and assign it the value of a backslash later on.

let mut start = '\';

however, the compiler throws this error:

error[E0762]: unterminated character literal
  --> src/main.rs:35:19
   |
35 |   let mut start = '\';
   |

I have already tried using “and "" instead of ” but the error persists. Why is this??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have to escape the \ like so: '\\' to get a char or like this: "\\" if you want to have a &str
If you later want to edit that variable like the mut suggests you probably want a proper String like this:
String::from("\\")

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading