#C Sharp Raw String Literals
17 messages · Page 1 of 1 (latest)
just saw this proposal for c# raw string literals and i think they're a step ahead of rust raw string literals. what do we think of them? https://github.com/dotnet/csharplang/blob/main/proposals/raw-string-literal.md
I like the idea that it features https://docs.rs/indoc logic in and of itself, but I do believe that there are use cases where that's desirable, and others where it isn't. So I like that Rust has the latter, I'd just wish there be a raw string literal modifier to opt into the former
github crates-io docs-rs
Although I have to admit that using the end of the string literal as a heuristic to guess the caller's intent is quite nifty. It won't cover 100% of use cases, but it will be a very handy an intuitive way of supporting 99.9%, while still having a convoluted way to write the 0.01% remaining percent (using concat!, or something like that).
my reaction too
this is so neat
I like it, but I don't like that """"<- this should be in the string""" won't work for obvious reasons
I definitely prefer rust's take, of using an unambiguous prefix to the opening quote.
I think it would be nice to have both "strings that can contain unescaped quotes but aren't raw" and "raw strings" as options in rust, like idk an s#"I'm not a "raw string"\nSo I contain a literal newline. But I can still contain unescaped quotes"# in addition to the usual raw strings.
(not an actual proposal for the syntax, I like the idea of eventually having something like s"" as Strings. I wonder if you could just do ##"some "string" here"## without needing a letter prefixing the whole construct, or if that would lead to ambiguity in parsing)
Agreed, encountering a "some \"thing\"\nfoo" and then thinking about using a r#"…"# string instead feels like <see picture below>
I'm unfortunately unfamiliar with the image you're referring to, at least by that description
Ah yep
in rust you can do:
?play rs let lit = r###"hello """ ## """" world "###; println!("{lit}");
hello """ ## """" world