udoprog / genco

A whitespace-aware quasiquoter for beautiful code generation.
Apache License 2.0
181 stars 11 forks source link

Recommended way to put a $variable inside of a "string literal" ? #33

Closed rrichardson closed 1 year ago

rrichardson commented 1 year ago

I need to create custom, error messages, so I want string literals and format-strings that looks like :

format!("Error: Missing field: $(fieldname) - {} ", error.to_string())

But I can't seem to come up with a way that makes the syntax checker happy, or if it does the $() is rendered as a string and not resolved to the value.

rrichardson commented 1 year ago

Ah. I think I found a way:

let msg = format!($[str](Error: Missing field $[const](fieldname) - {}), error.to_string());