How to declare a multiline string literal in Rust? Syntax and escaping
Hello, colleagues! I've just started learning Rust and encountered a problem when working with long strings. I need to declare a string literal that spans multiple lines, for example, to store an SQL query, JSON template, or just a long text with line breaks.\n\nIn other languages, like Python, I can use triple quotes `"""..."""` or backticks. In C#, there are `@""` strings. But in Rust, I tried simply breaking the string onto a new line inside double quotes — the compiler gives an error.\n\nHere's an example of what I'm trying to do:\n\n```rust\nlet query = "SELECT * FROM users\nWHERE age > 18\nORDER BY name";\n```\n\nThe compiler says: `error: unterminated double quote string`. I understand that Rust doesn't like line breaks inside regular strings. But what should I do then? I need the
No answers yet.
Log in to leave an answer
Blogs
Testing in PHP: Unit, Integration, E2E — A Complete Guide
SOLID Principles in JavaScript: Advanced Implementation and Code Examples
Java Application Security: Top 10 Vulnerabilities for Beginners
Monitoring JavaScript Applications: Metrics and Alerts at an Advanced Level