Fixed mistakes and missing semicolon in tupal

This commit is contained in:
Tanish-Eagle
2022-04-20 23:11:39 +05:30
parent 631265386d
commit 942d8c6671

View File

@ -6,29 +6,29 @@ fn main() {
let _t0: (u8,i16) = (0, -1); let _t0: (u8,i16) = (0, -1);
// Tuples can be tuple's members // Tuples can be tuple's members
let _t1: (u8, (i16, u32)) = (0, (-1, 1)); let _t1: (u8, (i16, u32)) = (0, (-1, 1));
// fill the blanks to make the code work // Fill the blanks to make the code work
let t: (u8, __, i64, __, __) = (1u8, 2u16, 3i64, "hello", String::from(", world")); let t: (u8, __, i64, __, __) = (1u8, 2u16, 3i64, "hello", String::from(", world"));
println!("Success!") println!("Success!");
} }
``` ```
2. 🌟 Members can be extracted from the tuple using indexing. 2. 🌟 Members can be extracted from the tuple using indexing.
```rust,editable ```rust,editable
// make it works // Make it work
fn main() { fn main() {
let t = ("i", "am", "sunface"); let t = ("i", "am", "sunface");
assert_eq!(t.1, "sunface"); assert_eq!(t.1, "sunface");
println!("Success!") println!("Success!");
} }
``` ```
3. 🌟 Long tuples cannot be printed 3. 🌟 Long tuples cannot be printed
```rust,editable ```rust,editable
// fix the error // Fix the error
fn main() { fn main() {
let too_long_tuple = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13); let too_long_tuple = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
println!("too long tuple: {:?}", too_long_tuple); println!("too long tuple: {:?}", too_long_tuple);
@ -41,14 +41,14 @@ fn main() {
fn main() { fn main() {
let tup = (1, 6.4, "hello"); let tup = (1, 6.4, "hello");
// fill the blank to make the code work // Fill the blank to make the code work
let __ = tup; let __ = tup;
assert_eq!(x, 1); assert_eq!(x, 1);
assert_eq!(y, "hello"); assert_eq!(y, "hello");
assert_eq!(z, 6.4); assert_eq!(z, 6.4);
println!("Success!") println!("Success!");
} }
``` ```
@ -57,14 +57,14 @@ fn main() {
fn main() { fn main() {
let (x, y, z); let (x, y, z);
// fill the blank // Fill the blank
__ = (1, 2, 3); __ = (1, 2, 3);
assert_eq!(x, 3); assert_eq!(x, 3);
assert_eq!(y, 1); assert_eq!(y, 1);
assert_eq!(z, 2); assert_eq!(z, 2);
println!("Success!") println!("Success!");
} }
``` ```
@ -72,13 +72,13 @@ fn main() {
```rust,editable ```rust,editable
fn main() { fn main() {
// fill the blank, need a few computations here. // Fill the blank, need a few computations here.
let (x, y) = sum_multiply(__); let (x, y) = sum_multiply(__);
assert_eq!(x, 5); assert_eq!(x, 5);
assert_eq!(y, 6); assert_eq!(y, 6);
println!("Success!") println!("Success!");
} }
fn sum_multiply(nums: (i32, i32)) -> (i32, i32) { fn sum_multiply(nums: (i32, i32)) -> (i32, i32) {