From 0abcdeed42957ca805a3a7475fb3f14085af346e Mon Sep 17 00:00:00 2001 From: mo8it Date: Wed, 19 Jun 2024 14:25:29 +0200 Subject: [PATCH] primitive_types6 solution --- .../04_primitive_types/primitive_types6.rs | 14 +++++--------- rustlings-macros/info.toml | 2 +- .../04_primitive_types/primitive_types6.rs | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/exercises/04_primitive_types/primitive_types6.rs b/exercises/04_primitive_types/primitive_types6.rs index 83cec24..a97e531 100644 --- a/exercises/04_primitive_types/primitive_types6.rs +++ b/exercises/04_primitive_types/primitive_types6.rs @@ -1,21 +1,17 @@ -// Use a tuple index to access the second element of `numbers`. You can put the -// expression for the second element where ??? is so that the test passes. - fn main() { // You can optionally experiment here. } #[cfg(test)] mod tests { - use super::*; - #[test] fn indexing_tuple() { let numbers = (1, 2, 3); - // Replace below ??? with the tuple indexing syntax. - let second = ???; - assert_eq!(2, second, - "This is not the 2nd number in the tuple!") + // TODO: Use a tuple index to access the second element of `numbers` + // and assign it to a variable called `second`. + // let second = ???; + + assert_eq!(second, 2, "This is not the 2nd number in the tuple!"); } } diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml index e5f5877..cd85dcc 100644 --- a/rustlings-macros/info.toml +++ b/rustlings-macros/info.toml @@ -296,7 +296,7 @@ While you could use a destructuring `let` for the tuple here, try indexing into it instead, as explained in the last example of the 'Data Types -> The Tuple Type' section of the book: https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type -Now you have another tool in your toolbox!""" +Now, you have another tool in your toolbox!""" # VECS diff --git a/solutions/04_primitive_types/primitive_types6.rs b/solutions/04_primitive_types/primitive_types6.rs index 4e18198..9b7c277 100644 --- a/solutions/04_primitive_types/primitive_types6.rs +++ b/solutions/04_primitive_types/primitive_types6.rs @@ -1 +1,16 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +fn main() { + // You can optionally experiment here. +} + +#[cfg(test)] +mod tests { + #[test] + fn indexing_tuple() { + let numbers = (1, 2, 3); + + // Tuple indexing syntax. + let second = numbers.1; + + assert_eq!(second, 2, "This is not the 2nd number in the tuple!"); + } +}