mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-25 14:57:32 -05:00
modules1 solution
This commit is contained in:
parent
879f0cd5c6
commit
ecbe9b7324
3 changed files with 18 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
// TODO: Fix the compiler error about calling a private function.
|
||||||
mod sausage_factory {
|
mod sausage_factory {
|
||||||
// Don't let anybody outside of this module see this!
|
// Don't let anybody outside of this module see this!
|
||||||
fn get_secret_recipe() -> String {
|
fn get_secret_recipe() -> String {
|
||||||
|
|
|
@ -527,9 +527,8 @@ name = "modules1"
|
||||||
dir = "10_modules"
|
dir = "10_modules"
|
||||||
test = false
|
test = false
|
||||||
hint = """
|
hint = """
|
||||||
Everything is private in Rust by default-- but there's a keyword we can use
|
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
|
to make something public!"""
|
||||||
needs to be public."""
|
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "modules2"
|
name = "modules2"
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue