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

前端 未结 2 1491
孤街浪徒
孤街浪徒 2021-01-08 00:56

I have a small project which built with no issues when it was all in one big .rs file. I wanted to make it easier to work with, so I broke it up into modules, and the projec

相关标签:
2条回答
  • 2021-01-08 01:11

    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.

    0 讨论(0)
  • 2021-01-08 01:21

    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.

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