Created
May 29, 2014 15:56
-
-
Save mitchmindtree/357fafc1c9fa5db3b10d to your computer and use it in GitHub Desktop.
A question about Rust 'mod', 'crate' and 'use' usage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//--------------- main.rs --------------------- | |
extern crate rand; // Why do I have to use this here, when I've already done so in a.rs? | |
mod a; | |
mod b; | |
fn main() { | |
a::test(); | |
b::test(); | |
} | |
//-------------- a.rs --------------------- | |
extern crate rand; | |
use rand::{random, task_rng, Rng} | |
use b; | |
pub fn test() { | |
// Stuff where random, task_rng, Rng and b are used and printed... | |
} | |
//-------------- b.rs --------------------- | |
extern crate std; | |
use std::vec; | |
pub fn test() { | |
// Stuff where vec is used and printed... | |
} | |
/* | |
My Question: | |
Why is it that when I remove "extern crate rand;" from line 3 in main.rs | |
rustc fails to recognise "random, task_rng and Rng" when used in a.rs? I | |
ask this because rustc seems to recognise my usage of std::vec in b.rs | |
totally fine, despite only having used "extern crate std;" in b.rs and | |
not in main.rs like I have to for "extern crate rand;" | |
NOTE: all files are in the same directory. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The solution was:
extern crate std is
I ended up removing 'extern crate rand' from a.rs and 'extern crate std' from b.rs and everything works as expected.