From 0338b1cbdfa567d5f9580afef1d4483c7d275c32 Mon Sep 17 00:00:00 2001 From: mo8it Date: Sat, 8 Jun 2024 21:43:38 +0200 Subject: [PATCH] primitive_types3 solution --- exercises/04_primitive_types/primitive_types3.rs | 7 +++---- rustlings-macros/info.toml | 2 +- solutions/04_primitive_types/primitive_types3.rs | 12 +++++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/exercises/04_primitive_types/primitive_types3.rs b/exercises/04_primitive_types/primitive_types3.rs index 5095fc4..bef5579 100644 --- a/exercises/04_primitive_types/primitive_types3.rs +++ b/exercises/04_primitive_types/primitive_types3.rs @@ -1,12 +1,11 @@ -// Create an array with at least 100 elements in it where the ??? is. - fn main() { - let a = ??? + // TODO: Create an array with at least 100 elements in it where the ??? is. + // let a = ??? if a.len() >= 100 { println!("Wow, that's a big array!"); } else { println!("Meh, I eat arrays like that for breakfast."); - panic!("Array not big enough, more elements needed") + panic!("Array not big enough, more elements needed"); } } diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml index 59de7f2..fc0bee8 100644 --- a/rustlings-macros/info.toml +++ b/rustlings-macros/info.toml @@ -250,7 +250,7 @@ name = "primitive_types3" dir = "04_primitive_types" test = false hint = """ -There's a shorthand to initialize Arrays with a certain size that does not +There's a shorthand to initialize arrays with a certain size that doesn't require you to type in 100 items (but you certainly can if you want!). For example, you can do: diff --git a/solutions/04_primitive_types/primitive_types3.rs b/solutions/04_primitive_types/primitive_types3.rs index 4e18198..8dd109f 100644 --- a/solutions/04_primitive_types/primitive_types3.rs +++ b/solutions/04_primitive_types/primitive_types3.rs @@ -1 +1,11 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +fn main() { + // An array with 100 elements of the value 42. + let a = [42; 100]; + + if a.len() >= 100 { + println!("Wow, that's a big array!"); + } else { + println!("Meh, I eat arrays like that for breakfast."); + panic!("Array not big enough, more elements needed"); + } +}