Creating a new file based on template

I want to create a file named default.project.json with it's contents to be the default variable. The issue I am having is that I need to replace the name key in the json with & It won't let me format it because it isn't a string literal.

format! is a macro that runs at compile time instead of at runtime, so it requires the first argument to be a string literal. Something like let default = format!("your{}string{}here", &; would get you moving.
If you need the template to be dynamic I'm not sure there is a way to do it with format!, but there are a bunch of other templating crates out there e.g. has some more interesting information.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.