1
0
Fork 0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-05-19 15:36:07 +02:00

Add module exercises from jdm! 🎉

Fixes #9.
This commit is contained in:
Carol (Nichols || Goulding) 2015-09-17 22:21:56 -04:00
parent 6324eeafe7
commit 9336aed2b9
3 changed files with 96 additions and 0 deletions

File diff suppressed because one or more lines are too long

42
modules/modules1.rs Normal file
View File

@ -0,0 +1,42 @@
// Make me compile! Scroll down for hints :)
mod sausage_factory {
fn make_sausage() {
println!("sausage!");
}
}
fn main() {
sausage_factory::make_sausage();
}
// Everything is private in Rust by default-- but there's a keyword we can use
// to make something public! The compiler error should point to the thing that
// needs to be public.

47
modules/modules2.rs Normal file
View File

@ -0,0 +1,47 @@
// Make me compile! Scroll down for hints :)
mod us_presidential_frontrunners {
use self::democrats::HILLARY_CLINTON as democrat;
use self::republicans::DONALD_TRUMP as republican;
mod democrats {
pub const HILLARY_CLINTON: &'static str = "Hillary Clinton";
pub const BERNIE_SANDERS: &'static str = "Bernie Sanders";
}
mod republicans {
pub const DONALD_TRUMP: &'static str = "Donald Trump";
pub const JEB_BUSH: &'static str = "Jeb Bush";
}
}
fn main() {
println!("candidates: {} and {}",
us_presidential_frontrunners::democrat,
us_presidential_frontrunners::republican);
}
// The us_presidential_frontrunners module is trying to present an external
// interface (the `democrat` and `republican` constants) that is different than
// its internal structure (the `democrats` and `republicans` modules and
// associated constants). It's almost there except for one keyword missing for
// each constant.
// One more hint: I wish the compiler error, instead of saying "unresolved name
// `us_presidential_frontrunners::democrat`", could say "constant
// `us_presidential_frontrunners::democrat` is private"!