“unresolved import — maybe a missing extern” When extern declaration exists

孤人 提交于 2019-12-01 02:47:24

To quote from the Crates and Modules chapter of the Rust book:

[...] use declarations are absolute paths, starting from your crate root. self makes that path relative to your current place in the hierarchy instead.

The compiler is correct; there is no such thing as rand, because you've put it inside a module, so the correct path to it would be GameState::ballstate::rand, or self::rand from within the GameState::ballstate module.

You need to either move extern crate rand; to the root module or use self::rand within the GameState::ballstate module.

You need to put the extern crate rand; line in you main.rs and/or lib.rs file. No need to put it in the other files.

Perhaps it is related to this bug.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!