[英]error[E0277]: the trait bound `std::result::Result<_, Box<ArchiveBzip2Error>>: std::error::Error` is not satisfied
When I use this map
statement:当我使用这个
map
语句时:
.map(|mut entry| -> Result<Box<&str>, Box<dyn Error>> {
Ok(Box::new(entry.path().or_else(|e| Err(e))?
.file_name().ok_or(Err(Box::new(ArchiveBzip2Error::InvalidArchive)))?
.to_str()?
))
})
I get this error:我收到此错误:
error[E0277]: the trait bound `std::result::Result<_, Box<ArchiveBzip2Error>>: std::error::Error` is not satisfied
--> src/archive/bzip2file.rs:58:101
|
58 | ... .file_name().ok_or(Err(Box::new(ArchiveBzip2Error::InvalidArchive)))?
| ^ the trait `std::error::Error` is not implemented for `std::result::Result<_, Box<ArchiveBzip2Error>>`
|
= note: required because of the requirements on the impl of `From<std::result::Result<_, Box<ArchiveBzip2Error>>>` for `Box<dyn std::error::Error>`
= note: required by `from`
Why can I not use the ?
为什么我不能使用
?
operator for what appears to be a regular Result
instance?似乎是常规
Result
实例的运算符?
Here is the full code segment:这是完整的代码段:
match self.archive {
Some(a) => match a {
InnerArchive::ThingArchive(mut ta) =>
Ok(Box::new(ta.entries()?
.filter_map(|e| e.ok())
.map(|mut entry| -> Result<Box<&str>, Box<dyn Error>> {
Ok(Box::new(entry.path().or_else(|e| Err(e))?
.file_name().ok_or(Err(Box::new(ArchiveBzip2Error::InvalidArchive)))?
.to_str()?
))
})
)),
InnerArchive::ThingGzDecoder(tgd) =>
match tgd.header() {
Some(h) => match h.filename() {
Some(s) => Ok(Box::new(vec![&std::str::from_utf8(s)].iter())),
None => Err(Box::new(ArchiveBzip2Error::InvalidArchive)),
},
None => Err(Box::new(ArchiveBzip2Error::InvalidArchive)),
},
}
None => Err(Box::new(ArchiveBzip2Error::FailedInstantiationError))
}
Here is the full context from the IDE, with type hints:以下是 IDE 的完整上下文,带有类型提示:
The signature of ok_or
is ok_or
的签名是
pub fn ok_or<E>(self, err: E) -> Result<T, E>
So the argument to ok_or
is the error itself, not a Result<T, E>
value.所以
ok_or
的参数是错误本身,而不是Result<T, E>
值。 Rather than而不是
.file_name().ok_or(Err(Box::new(ArchiveBzip2Error::InvalidArchive)))?
Consider考虑
.file_name().ok_or(Box::new(ArchiveBzip2Error::InvalidArchive))?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.