The code below reports maybe upstream crate will add FromStr for &str and refuses to compile.
I want to know is there some resolution to make the code compiled?
trait a<T> {
fn parse(&self) -> Result<T, String>;
}
impl<T: FromStr> a<T> for OptVal
where
T::Err: fmt::Display,
{
fn parse(&self) -> Result<T, String> {
let stat = self.stat.load(Ordering::Relaxed);
if stat & 4 == 0 {
return Err("can't called before main".to_owned());
}
if stat & 8 != 0 {
return Err("not in subcommand context".to_owned());
}
match self.name().parse() {
Ok(v) => Ok(v),
Err(e) => Err(format!("{}", e)),
}
}
}
impl a<&'static str> for OptVal {
fn parse(&self) -> Result<&'static str, String> {
let stat = self.stat.load(Ordering::Relaxed);
if stat & 4 == 0 {
return Err("can't called before main".to_owned());
}
if stat & 8 != 0 {
return Err("not in subcommand context".to_owned());
}
Ok(self.name())
}
}