1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-04 16:16:14 +02:00

Merge pull request #133 from rastringer/patch-1

Adds speaker notes to Compound Types section
This commit is contained in:
Martin Geisler 2023-01-11 15:51:53 +01:00 committed by GitHub
commit d037d7b5c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,3 +24,27 @@ fn main() {
println!("2nd index: {}", t.1);
}
```
<details>
Key points:
Arrays:
*Arrays have elements of the same type, `T`, and length, `N`, which is a compile-time constant.
*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.
*Adding `#`, eg `{a:#?}`, invokes a "pretty printing" format, which can be easier to read.
Tuples:
*Like arrays, tuples have a fixed length.
*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.
</details>