Aggregate literals (arrays and structs)
Aggregate literals build compound values directly in source code:
- array literals:
[a, b, c] - struct literals:
Type{ field: value, ... }
Full reference: literals aggregate.
Example#
struct Pair {
a: int,
b: int,
}
fn main () -> int {
let xs: int[3] = [1, 2, 3];
let p: Pair = Pair{ a: xs[0], b: xs[2] };
return p.a + p.b;
}
See also#
- Full reference: literals aggregate
- Types: types
Source repository · Edit this page · View Markdown