Compound Types
Tuple assignment and access:
fn main() {
println!("1st index: {}", t.0);
println!("2nd index: {}", t.1);
Key points:
Arrays:
We can use literals to assign values to arrays.
In the main function, the print statement asks for the debug implementation with the
?
format parameter:{}
gives the default output, gives the debug output. We could also have used{a}
and{a:?}
without specifying the value after the format string.Adding
#
, eg{a:#?}
, invokes a “pretty printing” format, which can be easier to read.
Tuples group together values of different types into a compound type.
Fields of a tuple can be accessed by the period and the index of the value, e.g.
t.0
,t.1
.-
- You can think of it as
void
that can be familiar to you from other programming languages.
- You can think of it as