5 ms·
We can just use a crate for that and don't have to have this horrible comment like style that brings its own category of problems. https://docs.rs/indoc/latest/
by Blackarea 1y ago
We can just use a crate for that and don't have to have this horrible comment like style that brings its own category of problems. https://docs.rs/indoc/latest/indoc/ https://docs.rs/indoc/latest/indoc/
- Twey 1y agoAnd what if you do want to include two spaces at the beginning of the block (but not any of the rest of the indentation)? Choice of specific line-start marker aside, I think this is the best solution to the indented-string problem I've seen so far.
- gf000 1y agoI think Java's solution is much cleaner.
- IshKebab 1y agoFor those of us that haven't used Java for a decade... > In text blocks, the leftmost non-whitespace character on any of the lines or the leftmost closing delimiter defines where meaningful white space begins. From https://blogs.oracle.com/javamagazine/post/text-blocks-come-to-java https://blogs.oracle.com/javamagazine/post/text-blocks-come-... It's not a bad option but it does mean you can't have text where every line is indented. This isn't uncommon - e.g. think about code generation of a function body.
- Twey 1y agoRight, this is a pretty common syntax, but doesn't address the same problem as Zig's syntax. I've only seen two that do: the Zig approach, and a postprocessing ‘dedent’ step.
- gf000 1y agoWhy couldn't you have it? You just put the ending """ where you want it relative to the content.
- IshKebab 1y agoAh I see - didn't notice it includes the trailing """. Tbh I still prefer Zig's solution. It's more obvious. (Though they should have picked a less intrusive prefix, I'd have gone with a backtick.)