Ancestors

Toot

Written by Jan :rust: :ferris: on 2025-01-19 at 19:55

Some #Rust string literal #trivia - the following are equal:

let s = "one line string";

let s = "one line \

         string";

And these ones are also equal:

let lines = "a\nmultiline\nstring";

let lines = "a

multiline

string";

and now my favorite... πŸ₯

let lines = "a\n\

         multiline\n\

         string";

Playground:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a2c5a0e080a4fc56bb9ea8accac22a8b

[#]RustLang #RustTips #Strings

=> More informations about this toot | More toots from janriemer@floss.social

Descendants

Written by Rasmus Kaj πŸŽΌπŸ¦€ on 2025-01-19 at 20:41

@janriemer

My favorite is close to yours, but slightly different:

let s = "a\
        \nmultiline\
        \nstring.";

Indention is removed from the resulting string, but putting the \n first on the line makes it possible to add kept indention after the \n.

=> More informations about this toot | More toots from rkaj@mastodon.nu

Written by Jan :rust: :ferris: on 2025-01-19 at 20:50

@rkaj Oh wow, this is even better, indeed! 🀯

Thank you! πŸ™‚

=> More informations about this toot | More toots from janriemer@floss.social

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113856774246752603
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
262.423686 milliseconds
Gemini-to-HTML Time
0.570252 milliseconds

This content has been proxied by September (3851b).