1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-28 11:31:32 +02:00

Speaker note tweaks for compound types

This commit is contained in:
Marko Zagar
2023-01-12 18:51:37 +01:00
parent 7a2ffda266
commit 529d4bf20c

View File

@ -26,16 +26,21 @@ fn main() {
``` ```
<details> <details>
Key points: Key points:
Arrays: Arrays:
* Arrays have elements of the same type, `T`, and length, `N`, which is a compile-time constant. * Arrays have elements of the same type, `T`, and length, `N`, which is a compile-time constant.
Note that the length of the array is *part of its type*, which means that `[u8; 3]` and
`[u8; 4]` are considered two different types.
* We can use literals to assign values to 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: `{a}` gives the default output, `{a:?}` gives the debug output. * 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. * Adding `#`, eg `{a:#?}`, invokes a "pretty printing" format, which can be easier to read.
@ -45,6 +50,11 @@ Tuples:
* Tuples group together values of different types into a compound type. * Tuples group together values of different types into a compound type.
* Fields that can be accessed by the period and the index of the value, e.g. `t.0`, `t.1`. * Fields of a tuple can be accessed by the period and the index of the value, e.g. `t.0`, `t.1`.
* The empty tuple `()` is also known as the "unit type". It is both a type, and
the only valid value of that type - that is to say both the type and its value
are expressed as `()`. It is used to indicate, for example, that a function or
expression has no return value, as we'll see in a future slide.
</details> </details>