udoprog/genco

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

rrichardson opened this issue · 1 comments

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.

Ah. I think I found a way:

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