title: Returning and using a generic type with match
body: <p>I'm working on a simple Rust app that accepts stdin and acts on the basis of it. I'd like to have each command return a vector of results.</p>
  
  <p>Different commands may return differently typed vectors; the <code>list</code> method returns a vector of <code>PathBuf</code>s, but the default match arm returns strings: </p>
  
  <pre><code>use std::{io, fs};
  use std::path::PathBuf;
  
  fn main() {
      let mut input = String::new();
      io::stdin().read_line(&amp;mut input).expect("Failed to read line");
      let chars_to_trim: &amp;[char] = &amp;['\n'];
      let trimmed_input: &amp;str = input.trim_matches(chars_to_trim);
  
      let no_match = vec!["No Match"];
  
      let result = match trimmed_input {
          "list" =&gt; list(),
          _ =&gt; no_match,
      };
  }
  
  fn list() -&gt; Vec&lt;PathBuf&gt; {
      println!("{}", "list of lockfiles here");
      let entries = fs::read_dir("/tmp").expect("Failed to read /tmp");
      let all: Result&lt;_, _&gt; = entries.map(|entry| entry.map(|e| e.path())).collect();
      all.expect("Unable to read an entry")
  }
  </code></pre>
  
  <p>This causes compilation to fail:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: match arms have incompatible types
    --&gt; src/main.rs:12:22
     |
  12 |         let result = match trimmed_input {
     |                      ^ expected struct `std::path::PathBuf`, found &amp;str
     |
     = note: expected type `std::vec::Vec&lt;std::path::PathBuf&gt;`
     = note:    found type `std::vec::Vec&lt;&amp;str&gt;`
  note: match arm with an incompatible type
    --&gt; src/main.rs:14:18
     |
  14 |             _ =&gt; no_match,
     |                  ^^^^^^^^
  </code></pre>
  
  <p>What is the idiomatic Rust way to handle this? I've read through the documentation on generics but I'm not sure how to apply it.</p>