• nous@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    You can give it variables:

    let foo = 4;
    let bar = "bar";
    format!("{foo}{bar}");
    

    If you have a format string that long with arbatary expressions putting them all raw in the format string is not going to improve much. Better to give them actual names first.

    • Walnut356@programming.devOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      in this case it’s about 80% function calls. They’re convenience functions for assembly instructions, so they’re of the form:

      load(Reg::D, "A"),
      load_const(5),
      

      which is more useful than variables would be. I guess i could use .join or a crate like concat_string? Either way i sorely miss arbitrary expression format strings from python =(

      • coloredgrayscale@programming.dev
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 year ago

        Creating an array of the function calls, and joining those seems more readable in that case.

        Plus you don’t have to take care that you use the correct number of placeholders.