title: How to escape curly braces in a format string in Rust
body: <p>I want to write this</p>
  
  <pre><code>write!(f, "{ hash:{}, subject: {} }", self.hash, self.subject)
  </code></pre>
  
  <p>But since curly braces have special meaning for formatting it's clear that I can't place the outer curly braces like that without escaping. So I tried to escape them.</p>
  
  <pre><code>write!(f, "\{ hash:{}, subject: {} \}", self.hash, self.subject)
  </code></pre>
  
  <p>Rust doesn't like that either. Then I read this:</p>
  
  <blockquote>
    <p>The literal characters {, }, or # may be included in a string by preceding them with the \ character. Since \ is already an escape character in Rust strings, a string literal using this escape will look like "\{".</p>
  </blockquote>
  
  <p>So I tried</p>
  
  <pre><code>write!(f, "\\{ hash:{}, subject: {} \\}", self.hash, self.subject)
  </code></pre>
  
  <p>But that's also not working. :-(</p>