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 = "stackoverflow-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-proto
是imap
机箱的依赖项,代码在将依赖项imap-proto = "0.10.2"
添加到我的项目后编译。
有没有一种方法可以在不显式依赖于imap-proto
机箱的情况下销毁变量bodystructure
?只为destructure变量添加额外依赖项的要求对我来说似乎很奇怪。我做错了什么吗?
根据我对imap机箱文档的阅读,bodystructure函数返回一个Option<amp;车身结构<'a>gt;,其中BodyStructure是在imap原型机箱中定义的枚举。所以我认为答案是否定的,除了imap之外,你还必须将imap-proto作为一个依赖项。
来源:https://docs.rs/imap/2.4.1/imap/types/struct.Fetch.html#method.bodystructure