Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a type from dependence's dependence?

Tags:

rust

reqwest

I'd like to use a type returned by a function in crate A that is actually defined in crate B, but crate A doesn't reexport it.

Although I can explicitly add crate B in my Cargo.toml, I'm not sure how to keep its version sync with the one used in crate A.

To be more specific, the type is url::ParseError, crate A is reqwest and crate B is url.

like image 981
whfuyn Avatar asked Nov 06 '22 03:11

whfuyn


1 Answers

There are no "official" guidelines around this issue. There was a 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 and it was decided to not re-export 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.

like image 134
Ibraheem Ahmed Avatar answered Nov 30 '22 21:11

Ibraheem Ahmed