title: Get the file name as a string in Rust
body: <p>I am trying to get the file name of a given string using the following code:</p>
  <pre class="lang-rust prettyprint-override"><code>fn get_filename() -&gt; Result&lt;(), std::io::Error&gt; {
      let file = &quot;folder/file.text&quot;;
      let path = Path::new(file);
      let filename = path.file_name()?.to_str()?;
      println!(&quot;{}&quot;,filename);
      Ok(())
  }
  </code></pre>
  <p>But I get this error:</p>
  <pre class="lang-none prettyprint-override"><code>error[E0277]: `?` couldn't convert the error to `std::io::Error`
  </code></pre>
  <p>The original code didn't want to return <code>Result</code>, but that's the only way to use <code>?</code>. How can I fix this?</p>