Multiple return types from a method
Solution 1:
You could design a solution around trait
, but it would probably be much more work than simply adapting your current solution slightly:
struct DateBased{
series: String,
date: Date
}
struct SeasonBased{
series: String,
season: i32,
episode: i32
}
enum ParsedFile{
Date(DateBased),
Season(SeasonBased),
// etc
}
fn _populate_datebased(file: DateBased) -> Result<PopulatedFile, TvdbError>;
fn _populate_seasonbased(file: SeasonBased) -> Result<PopulatedFile, TvdbError>;
fn populate(f: ParsedFile) -> Result<PopulatedFile, TvdbError> {
return match f {
ParsedFile::Date(d) => _populate_datebased(d),
// ...
}
}
You can combine enum
and struct
in Rust, and I personally find it worth it to put name on things specifically because it allows manipulating them more easily.