Unable to find symbols from extern crates included with `use`

后端 未结 1 2046
天涯浪人
天涯浪人 2020-12-03 19:48

I\'m trying to use some Rust libraries from crates on Github. This is the first time I\'ve tried to do this. The code, lifted from an \"html\" library example, begins like t

相关标签:
1条回答
  • 2020-12-03 20:50

    The compiler gave you the answer you need.

    Your extern crate statements are inside a module, and use statements require absolute paths. That is, when you say use url::Url; inside the interactive_test module, what you are actually saying is "use url::Url which is defined in the root module", which it isn't.

    What you need to do is prefix the path with self:: to tell it to look in the current module. You can also use super:: to access the parent module (if that ever comes up).

    Personally, I get around this by putting all my extern crate statements in the root module, which also serves as a kind of program-wide list of external crates being used.

    0 讨论(0)
提交回复
热议问题