Rust mod/path question
This file contains 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
/* | |
Everything is in a single crate. The directory structure is as follows: | |
. | |
├── b | |
│ └── mod.rs | |
├── c | |
│ └── mod.rs | |
├── d | |
│ └── mod.rs | |
└── main.rs | |
*/ | |
// -------------------- main.rs | |
mod b; | |
mod c; | |
fn main() { | |
println!("{}", b::foo()); | |
println!("{}", c::bar()); | |
} | |
// -------------------- b/mod.rs | |
#[path="../d/mod.rs"] | |
mod d; | |
pub fn foo() -> int { | |
1 + d::baz() | |
} | |
// -------------------- c/mod.rs | |
#[path="../d/mod.rs"] | |
mod d; | |
pub fn bar() -> int { | |
2 + d::baz() | |
} | |
// -------------------- d/mod.rs | |
pub fn baz() -> int { | |
10 | |
} | |
/* My questions are these: | |
1) In a single crate, is there a way for modules b and c to | |
access baz() in d without using the #[path] directive | |
(which, I gather, is non-idiomatic)? | |
2) If the answer to 1) is no, then is the only way to do this | |
by putting b and c in one crate and d in another crate? Is that | |
the idiomatic solution? | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment