mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-21 05:32:22 -05:00
primitive_types6 solution
This commit is contained in:
parent
532c9ebb30
commit
0abcdeed42
3 changed files with 22 additions and 11 deletions
|
@ -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() {
|
fn main() {
|
||||||
// You can optionally experiment here.
|
// You can optionally experiment here.
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn indexing_tuple() {
|
fn indexing_tuple() {
|
||||||
let numbers = (1, 2, 3);
|
let numbers = (1, 2, 3);
|
||||||
// Replace below ??? with the tuple indexing syntax.
|
|
||||||
let second = ???;
|
|
||||||
|
|
||||||
assert_eq!(2, second,
|
// TODO: Use a tuple index to access the second element of `numbers`
|
||||||
"This is not the 2nd number in the tuple!")
|
// and assign it to a variable called `second`.
|
||||||
|
// let second = ???;
|
||||||
|
|
||||||
|
assert_eq!(second, 2, "This is not the 2nd number in the tuple!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
indexing into it instead, as explained in the last example of the
|
||||||
'Data Types -> The Tuple Type' section of the book:
|
'Data Types -> The Tuple Type' section of the book:
|
||||||
https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type
|
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
|
# VECS
|
||||||
|
|
||||||
|
|
|
@ -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!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue