From ecbe9b7324364e94f7c6b4a4dd279fb90f5a938e Mon Sep 17 00:00:00 2001 From: mo8it Date: Sat, 22 Jun 2024 13:12:39 +0200 Subject: [PATCH] modules1 solution --- exercises/10_modules/modules1.rs | 1 + rustlings-macros/info.toml | 5 ++--- solutions/10_modules/modules1.rs | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/exercises/10_modules/modules1.rs b/exercises/10_modules/modules1.rs index 931a3e26..d97ab23a 100644 --- a/exercises/10_modules/modules1.rs +++ b/exercises/10_modules/modules1.rs @@ -1,3 +1,4 @@ +// TODO: Fix the compiler error about calling a private function. mod sausage_factory { // Don't let anybody outside of this module see this! fn get_secret_recipe() -> String { diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml index 7607650b..97d7e07d 100644 --- a/rustlings-macros/info.toml +++ b/rustlings-macros/info.toml @@ -527,9 +527,8 @@ name = "modules1" dir = "10_modules" test = false hint = """ -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.""" +Everything is private in Rust by default. But there's a keyword we can use +to make something public!""" [[exercises]] name = "modules2" diff --git a/solutions/10_modules/modules1.rs b/solutions/10_modules/modules1.rs index 4e181989..873b4127 100644 --- a/solutions/10_modules/modules1.rs +++ b/solutions/10_modules/modules1.rs @@ -1 +1,15 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +mod sausage_factory { + fn get_secret_recipe() -> String { + String::from("Ginger") + } + + // Added `pub` before `fn` to make the function accessible outside the module. + pub fn make_sausage() { + get_secret_recipe(); + println!("sausage!"); + } +} + +fn main() { + sausage_factory::make_sausage(); +}