I'm trying to write a generic command line parser. I'm having trouble with "default" values for generic types. cmd.invoke() returns a Result<K, E>, so there's no problem there, but how do I represent a placeholder or default value for E when cmd_to_invoke is a None? In C#, I could use default(E). Is there a construct like this in Rust?
pub struct Cmd<K, E> {
cmds: Vec<Cmd<K, E>>,
}
impl<K, E> Cmd<K, E> {
pub fn invoke(&mut self, cmd_name: &str) -> Result<K, E> {
let cmd_to_invoke = self.cmds.iter_mut().find(|cmd| cmd.name == cmd_name);
if let Some(cmd) = cmd_to_invoke {
cmd.invoke()
} else {
// Some default / placeholder value for E
Err(/* ? */)
}
}
}