1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-31 06:37:39 +02:00
comprehensive-rust/src/basic-syntax/compound-types.md

27 lines
575 B
Markdown
Raw Normal View History

2022-12-21 16:36:30 +01:00
# Compound Types
| | Types | Literals |
|--------|---------------------|--------------------------|
| Arrays | `[T; N]` | `[20, 30, 40]`, `[0; 3]` |
| Tuples | `(T1, T2, T3)` | `('x', 1.2, 0)` |
2022-12-21 16:36:30 +01:00
Array assignment and access:
```rust,editable
fn main() {
let mut a: [i8; 10] = [42; 10];
a[5] = 0;
println!("a: {:?}", a);
}
```
Tuple assignment and access:
```rust,editable
fn main() {
let t: (i8, bool) = (7, true);
println!("1st index: {}", t.0);
println!("2nd index: {}", t.1);
}
```