genco icon indicating copy to clipboard operation
genco copied to clipboard

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

Open rrichardson opened this issue 3 years ago • 1 comments
trafficstars

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 avatar Sep 21 '22 17:09 rrichardson

Ah. I think I found a way:

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

rrichardson avatar Sep 21 '22 17:09 rrichardson