简体   繁体   English

错误[E0277]:特征绑定`std::result::Result&lt;_, Box<archivebzip2error> &gt;: std::error::Error` 不满足</archivebzip2error>

[英]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.

相关问题 如何解决错误E0277:特质绑定`[usize]:std :: marker :: Sized`不满意? - How can I fix the error E0277: the trait bound `[usize]: std::marker::Sized` is not satisfied? error[E0277]: 特征绑定 `NotesDs: Serialize` 不满足 - error[E0277]: the trait bound `NotesDs: Serialize` is not satisfied Rust: Error[E0277]: trait bound `{integer}: SampleRange&lt;_&gt;` 不满足 - Rust: Error[E0277]: the trait bound `{integer}: SampleRange<_>` is not satisfied 扭曲错误:错误[E0277]:特征绑定`impl warp::Future: warp::filter::FilterBase`不满足 - Warp error: error[E0277]: the trait bound `impl warp::Future: warp::filter::FilterBase` is not satisfied 错误[E0277]:特征绑定“ my_struct :: MyStruct:my_trait :: MyTrait”不满足 - error[E0277]: the trait bound `my_struct::MyStruct: my_trait::MyTrait` is not satisfied 错误[E0277]:不满足特征绑定`Request: serde::ser::Serialize` - error[E0277]: the trait bound `Request<Body>: serde::ser::Serialize` is not satisfied 错误[E0277]:特征绑定`Vec<tokenstream2> : ToTokens` 不满意</tokenstream2> - error[E0277]: the trait bound `Vec<TokenStream2>: ToTokens` is not satisfied structopt: error[E0277]: trait bound `String: From<&OsStr>` - structopt: error[E0277]: the trait bound `String: From<&OsStr>` error[E0277]: 特性绑定 `Project: Serialize` 不满足,注意:`near_sdk::serde_json::to_vec` 中的绑定要求 - error[E0277]: the trait bound `Project: Serialize` is not satisfied, note: required by a bound in `near_sdk::serde_json::to_vec` 实现Read trait:trait绑定`std :: error :: Error +&#39;static:std :: marker :: Sized`不满足 - Implementing Read trait : trait bound `std::error::Error + 'static: std::marker::Sized` is not satisfied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM