I have a simple file, in which I want to add some value from rust in the place of {}
holders. Is there a way to mimic passing the content
variable like if the string is hardcoded there? If not, how can I achieve a basic templating system with built-in rust features?
- file.txt:
Hello this is from rust: {}
- Rust code:
use std::fs;
let mut content = fs::read_to_string("file.txt").unwrap().as_mut_str();
format!(content, "SDSD");
Rust is giving me this error:
format argument must be a string literal rustc
main.rs(17, 13): you might be missing a string literal to format with: `"{} {}",
- Cargo check:
error: format argument must be a string literal
--> src\main.rs:17:13
|
17 | format!(content, "SDSD");
| ^^^^^^^
|
help: you might be missing a string literal to format with
|
17 | format!("{} {}", content, "SDSD");
| ++++++++
error: could not compile `web_server` due to previous error
Edit:
I know that format requires a string literal, like I asked above, I wanted to know if there is a way that can "mimic" a variable reference as a string literal.
The question there asks for the solution to this error (just use format!("{}", contents)
), which is not the solution of this question.