Skip to content

Instantly share code, notes, and snippets.

@Dr-Emann
Created May 29, 2014 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dr-Emann/77f6beb2e86687a4f325 to your computer and use it in GitHub Desktop.
Save Dr-Emann/77f6beb2e86687a4f325 to your computer and use it in GitHub Desktop.
Demonstration of rust modules in files
//--------------- main.rs ---------------------
use a::b;
mod a;
mod c;
fn main() {
println!("{}", a::foo);
c::foobar();
println!("{}", b::bar);
}
//-------------- a/mod.rs ---------------------
pub mod b;
pub static foo: int = 40;
//-------- a/b.rs (or a/b/mod.rs) -------------
pub static bar: f64 = 1.1;
//----------------- c.rs ----------------------
// no need to use mod
use a::b;
pub fn foobar() {
println!("{}", b::bar);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment