title: Best way to format a file name based on another path in Rust
body: <p>Is there a more concise way of writing the following?</p>
  
  <pre class="lang-rust prettyprint-override"><code>use std::path::Path;
  
  let path = Path::new("/path/to/foo.txt");
  let formatted = &amp;format!("{}%d.{}", path.file_stem().unwrap().to_str().unwrap(), path.extension().unwrap().to_str().unwrap());
  
  assert_eq!("foo%d.txt", formatted);
  </code></pre>
  
  <p>(I want to convert <code>/path/to/foo.txt</code> to <code>foo%d.txt</code>)</p>