Web*_*rix 6 string error-handling traits rust
我正在尝试创建Error实现的枚举to_string().我曾试图derive(Debug)为他们,但似乎还不够.
这是我正在研究的枚举:
#[derive(Debug, Clone)]
pub enum InnerError {
InnerErrorWithDescription(String),
}
#[derive(Debug, Clone)]
pub enum OuterError {
OuterErrorWithDescription(String),
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是:
// result type <T,InnerErrorWithDescription>
result.map_err(|err| { Error::OuterErrorWithDescription(err.to_string())}) // .to_string() is not available
Run Code Online (Sandbox Code Playgroud)
我无法将InnerError枚举类型转换为OuterError.
我应该改变什么来实现它?
我在这里写了一个编写枚举类型及其值的例子:
但是,我仍然必须在匹配情况下指定类型和它的描述,是否有更通用的实现?