I have the following function in which Command is a trait
pub fn parse_arguments(matches: ArgMatches) -> Result<impl Command, &'static str>
Inside the function body, I want to return different implementations of Command depending on the arguments like
match args.subcommand() {
("init", Some(args)) => {
Ok(Init::new(args))
}
("btc", Some(args)) => {
Ok(ImportBtc::new(args))
},
("grin", Some(args)) => {
Ok(ImportGrin::new(args))
},
_ => Err ("Invalid subcommand supplied")
}
Compilation will fail with an error:
expected struct `commands::cmd_types::Init`, found struct `commands::cmd_types::ImportBtc`
and similar for the ImportGrin return line.
Have I misunderstood how impl Trait works?