如何从依赖的依赖中使用类型?

How to use a type from dependence's dependence?

我想使用实际上在 crate B 中定义的 crate A 中的函数返回的类型,但 crate A 不会重新导出它。

尽管我可以在我的 Cargo.toml 中明确添加 crate B,但我不确定如何使其版本与 crate A 中使用的版本保持同步。

更具体地说,类型是 url::ParseError,箱子 A 是 reqwest,箱子 B 是 url

没有关于此问题的“官方”指南。有一个discussion regarding best practices a while back with no definite conclusion. Many crates wrap external types so they aren't exposed directly, or they re-export items. This specific issue with reqwest was discussed here决定不转口url::ParseError:

My personal feeling is that this is somewhat niche, and so for those who don't need it, it just clutters the API. For anyone who does need to inspect for this specific error, they can add the url crate as a dependency.