From 990c68efcba8e1e2b7f2d8c5b6c16885d3920010 Mon Sep 17 00:00:00 2001 From: mo8it Date: Sat, 25 May 2024 16:31:21 +0200 Subject: [PATCH] primitive_types1 solution --- exercises/04_primitive_types/primitive_types1.rs | 8 +++----- rustlings-macros/info.toml | 5 ++++- solutions/04_primitive_types/primitive_types1.rs | 12 +++++++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/exercises/04_primitive_types/primitive_types1.rs b/exercises/04_primitive_types/primitive_types1.rs index 0002651d..750d6e55 100644 --- a/exercises/04_primitive_types/primitive_types1.rs +++ b/exercises/04_primitive_types/primitive_types1.rs @@ -1,14 +1,12 @@ -// Fill in the rest of the line that has code missing! - fn main() { - // Booleans (`bool`) - let is_morning = true; if is_morning { println!("Good morning!"); } - let // Finish the rest of this line like the example! Or make it be false! + // TODO: Define a boolean variable with the name `is_evening` before the `if` statement below. + // The value of the variable should be the negation (opposite) of `is_morning`. + // let … if is_evening { println!("Good evening!"); } diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml index 39fc5c4d..59de7f25 100644 --- a/rustlings-macros/info.toml +++ b/rustlings-macros/info.toml @@ -234,7 +234,10 @@ hint = "No hints this time ;)" name = "primitive_types1" dir = "04_primitive_types" test = false -hint = "No hints this time ;)" +hint = """ +In Rust, a boolean can be negated using the operator `!` before it. +Example: `!true == false` +This also works with boolean variables.""" [[exercises]] name = "primitive_types2" diff --git a/solutions/04_primitive_types/primitive_types1.rs b/solutions/04_primitive_types/primitive_types1.rs index 4e181989..fac6ec04 100644 --- a/solutions/04_primitive_types/primitive_types1.rs +++ b/solutions/04_primitive_types/primitive_types1.rs @@ -1 +1,11 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +fn main() { + let is_morning = true; + if is_morning { + println!("Good morning!"); + } + + let is_evening = !is_morning; + if is_evening { + println!("Good evening!"); + } +}