5/5
# Tuple ## Example Execute the following command to run [`./solutions/examples/tuple.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/tuple/solutions/examples/tuple.rs) ```shell cargo run --example tuple ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/tuple/exercises/src/lib.rs) ### Exercise 1 ```rust pub fn first(t: (bool, u32, char)) -> bool { todo!(); } ``` Return the first element in the tuple `t`. ### Exercise 2 ```rust pub fn last(t: (bool, u32, char)) -> char { todo!(); } ``` Return the last element in the tuple `t`. ### Exercise 3 ```rust pub fn swap(t: (u32, u32)) -> (u32, u32) { todo!(); } ``` Swap the first and second elements of the tuple `t`. ## Test ```shell cargo test ```
Execute the following command to run ./solutions/examples/tuple.rs
Exercises are in ./exercises/src/lib.rs
Return the first element in the tuple t
.
Return the last element in the tuple t
.
Swap the first and second elements of the tuple t
.
An elemental exploration of Rust Tuples - Discover Rust's way of grouping multiple values of potentially different types into one compound type. You'll get hands-on experience accessing specific elements and swapping their order within a tuple.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025
Rust Developer
Rust Programming BasicsDuration: 6min
Duration: 18min
Duration: 47min
Duration: 15min
Duration: 19min
Duration: 8min
Duration: 12min
Duration: 46min
Duration: 14min
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on July 11, 2025