title: Multiple return types from a method
body: <p>I am trying to write a simple TV-episode file renamer in Rust.</p>
  
  <p>A filename is parsed, and might be one of several types (date-based, season/episode-number based etc). This parsed file is then turned into a "populated file" with data from a database (which is then formatted into a new filename)</p>
  
  <p>Initially I tried having the <code>parse</code> method take a filename and return an enum variant:</p>
  
  <pre><code>enum ParsedFile{
      DateBased{series: String, date: Date},
      SeasonBased{series: String, season: i32, episode: i32},
      // etc
  }
  
  
  fn parse(fname:&amp;str) -&gt; Option&lt;ParsedFile&gt;{
      ...
  }
  </code></pre>
  
  <p>This worked fine, however the methods to take the <code>ParsedFile</code> and do different things for each episode became messy</p>
  
  <p>For example, to separate the <code>ParsedFile-&gt;PopulatedFile</code> translation into separate methods, I have to match the variants, then destructure this in the method</p>
  
  <pre><code>struct PopulatedFile {
      seriesname: String,
      season: i32,
      episode: i32,
      episodename: String,
      airdate: Date,
  }
  
  fn _populate_seasonbased(file: ParsedFile) -&gt; Result&lt;PopulatedFile, TvdbError&gt;{
      // can't just access file.season or file.episode, have to destructure enum again
  }
  
  fn populate(f: ParsedFile) -&gt; Result&lt;PopulatedFile, TvdbError&gt; {
      return match f {
          ParsedFile::DateBased{..} =&gt; 
              _populate_datebased(f),
          // ...
      }
  }
  </code></pre>
  
  <p>This seemed really clunky, and I'm sure there must be a better way.</p>
  
  <p>It would be nicer to have each episode type as a separate struct, e.g:</p>
  
  <pre><code>struct DateBased{
      series: String,
      date: Date
  }
  struct SeasonBased{
      series: String,
      season: i32,
      episode: i32
  }
  </code></pre>
  
  <p>..then I could, say, implement a <code>ToPopulatedFile</code> trait for each episode type. However I couldn't find a way to write the <code>parse</code> method in this example (i.e write a method which might return a <code>DateBased</code> struct or a <code>SeasonBased</code> struct)</p>
  
  <p>Is there a good way to structure this?</p>