summaryrefslogtreecommitdiff
path: root/exercises/modules
diff options
context:
space:
mode:
authorolivia <olivia@fastmail.com>2018-11-09 20:31:14 +0100
committerolivia <olivia@fastmail.com>2018-11-09 20:31:14 +0100
commitf7846af7ac388652a6f80a2bbce926ba8f053062 (patch)
tree954ee36257047ac612654c5f35e18ed27deda97f /exercises/modules
parent850a13e9133fedb2fce27884902e0aab94da9692 (diff)
right let's try this one again
Diffstat (limited to 'exercises/modules')
-rwxr-xr-xexercises/modules/modules1.rs43
-rwxr-xr-xexercises/modules/modules2.rs45
2 files changed, 88 insertions, 0 deletions
diff --git a/exercises/modules/modules1.rs b/exercises/modules/modules1.rs
new file mode 100755
index 0000000..0e092c5
--- /dev/null
+++ b/exercises/modules/modules1.rs
@@ -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.
diff --git a/exercises/modules/modules2.rs b/exercises/modules/modules2.rs
new file mode 100755
index 0000000..164dfb0
--- /dev/null
+++ b/exercises/modules/modules2.rs
@@ -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.