How to define a multiline string constant in Rust? Syntax and examples
Hello everyone! I just started learning Rust and ran into a problem. I need to declare a string variable that contains multiple lines of text. In other languages, like Python, I can simply write:
```python
text = """This
is a multiline
string"""
```
But in Rust I try this:
```rust
let text = "This
is a multiline
string";
```
And the compiler gives an error: `error: unterminated double quote string`. I also tried escaping the newline characters with `\n`, but it's inconvenient for large texts, such as JSON, SQL queries, or long messages.
Please tell me what is the correct syntax for multiline string literals in Rust? Are there any specific features, for example, regarding indentation or whitespace? Thanks in advance!
No answers yet.
Log in to leave an answer