1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-11-27 22:38:18 +02:00

right let's try this one again

This commit is contained in:
olivia
2018-11-09 20:31:14 +01:00
parent 850a13e913
commit f7846af7ac
60 changed files with 130 additions and 939 deletions

43
exercises/modules/modules1.rs Executable file
View File

@@ -0,0 +1,43 @@
// modules1.rs
// 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.

45
exercises/modules/modules2.rs Executable file
View File

@@ -0,0 +1,45 @@
// modules2.rs
// 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.