title: How can I use a dynamic format string with the format! macro?
body: <p>I want to use the <code>format!</code> macro with a <code>String</code> as first argument, but because the macro expects a string literal, I am not able pass anything different to it.</p>
  <p>I want to do this to dynamically add strings into the current string for use in a view engine. I'm open for suggestions if there might be a better way to do it.</p>
  <pre><code>let test = String::from(&quot;Test: {}&quot;);
  let test2 = String::from(&quot;Not working!&quot;);
  println!(test, test2);
  </code></pre>
  <p>What I actually want to achieve is the below example, where main.html contains <code>{content}</code>.</p>
  <pre><code>use std::io::prelude::*;
  use std::fs::File;
  use std::io;
  
  fn main() {
      let mut buffer = String::new();
      read_from_file_using_try(&amp;mut buffer);
  
      println!(&amp;buffer, content=&quot;content&quot;);
  }
  
  fn read_from_file_using_try(buffer: &amp;mut String) -&gt; Result&lt;(), io::Error&gt; {
      let mut file = try!(File::open(&quot;main.html&quot;));
      try!(file.read_to_string(buffer));
      Ok(())
  }
  </code></pre>
  <p>So I want to print the contents of main.html after I formatted it.</p>