(英语不是我的母语;请原谅输入错误。)
在我的项目中,有一个错误类型:
pub type RvzResult<T> = Result<T, RvzError>;
#[derive(Error, Debug)]
pub enum RvzError {
// some error types...
,
OtherErr(Box<dyn Error>)
}
Run Code Online (Sandbox Code Playgroud)
有一天,我有一个Mutex对象并像这样使用它:
pub fn some_func() -> RvzResult<()> {
// ...
let lock = the_mutex.lock()?;
// ...
}
Run Code Online (Sandbox Code Playgroud)
但 rustc 不太高兴:error[E0277]: '?' couldn't convert the error to 'RvzError'
我尝试From像这样实现特征:
impl <T> From<PoisonError<T>> for RvzError {
fn from(err: PoisonError<T>) -> Self {
Self::OtherErr(Box::new(err))
}
}
Run Code Online (Sandbox Code Playgroud)
它失败了:error[E0310]: the parameter type 'T' may not live long enough
rust ×1