logoalt Hacker News

Rendelloyesterday at 7:13 PM2 repliesview on HN

Aside: one Zig (syntax) feature that I really missed in Rust is shown in the second code block, namely prefixed multi-line string literals à la:

    const text =
        \\This is a long comment
        \\But I can split it among lines arbitrarily
        \\And keep my indentation.
    ;
I've started using the Rust macro library `docstr` [1], which does the same thing:

    const TEXT: &'static str = docstr!(
        /// Now I can do it in Rust, too.
        /// I prefer this style a lot of the time
        /// for long texts.
    );
It even works with macros (example from the docs):

    let greeting: String = docstr!(format!
        /// Hello, my name is {name}.
        /// I am {} years old!
        age
    );
1. https://docs.rs/docstr/latest/docstr/

Replies

metaltyphoontoday at 12:26 AM

C# solves this so elegantly

   string text = """
      This is a long comment
      But I can split it
      And keep my indentation.
      """;
Gibbon1yesterday at 10:55 PM

In C you can do that.

   printf ("Things:\n"
     " thing1=%u\n"
     " thing2=%u\n"
     " thing3=%u\n",
        thing1,
        thing2,
        thing3);