如何从传递依赖中解构枚举?

How to destructure an enum from a transitive dependency?

src/main.rs:

fn main() {}

fn test(fetch: imap::types::Fetch) {
    // Variable of type &BodyStructure
    let bodystructure = fetch.bodystructure().unwrap();

    match bodystructure {
        imap_proto::BodyStructure::Basic { .. } => {}
        imap_proto::BodyStructure::Message { .. } => {}
        imap_proto::BodyStructure::Multipart { .. } => {}
        imap_proto::BodyStructure::Text { .. } => {}
    };
}

Cargo.toml:

[package]
name = "Whosebug-68445809"
version = "0.1.0"
edition = "2018"

[dependencies]
imap = "2.4.1"

# This dependency solves the problem
# imap-proto = "0.10.2"

代码无法编译:

error[E0433]: failed to resolve: use of undeclared crate or module `imap_proto`
 --> src/main.rs:8:9
  |
8 |         imap_proto::BodyStructure::Basic { .. } => {}
  |         ^^^^^^^^^^ use of undeclared crate or module `imap_proto`

error[E0433]: failed to resolve: use of undeclared crate or module `imap_proto`
 --> src/main.rs:9:9
  |
9 |         imap_proto::BodyStructure::Message { .. } => {}
  |         ^^^^^^^^^^ use of undeclared crate or module `imap_proto`

error[E0433]: failed to resolve: use of undeclared crate or module `imap_proto`
  --> src/main.rs:10:9
   |
10 |         imap_proto::BodyStructure::Multipart { .. } => {}
   |         ^^^^^^^^^^ use of undeclared crate or module `imap_proto`

error[E0433]: failed to resolve: use of undeclared crate or module `imap_proto`
  --> src/main.rs:11:9
   |
11 |         imap_proto::BodyStructure::Text { .. } => {}
   |         ^^^^^^^^^^ use of undeclared crate or module `imap_proto`

imap-protoimap crate 的依赖项,代码在将依赖项 imap-proto = "0.10.2" 添加到我的项目后编译。

有没有一种方法可以在不显式依赖 imap-proto crate 的情况下解构变量 bodystructure?仅添加额外依赖项以解构变量的要求对我来说似乎很奇怪。我做错了什么吗?

根据我对 imap crate 文档的阅读,bodystructure 函数 returns Option<&BodyStructure<'a>>,其中 BodyStructure 是在 imap-proto crate 中定义的枚举。所以我认为答案是否定的,除了 imap 之外,您还必须将 imap-proto 作为依赖项包含在内。

来源:https://docs.rs/imap/2.4.1/imap/types/struct.Fetch.html#method.bodystructure