aboutsummaryrefslogtreecommitdiff
path: root/doc/langref/destructuring_arrays.zig
blob: e58f7b73316b961fc9214145c450979a593f5e50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const print = @import("std").debug.print;

fn swizzleRgbaToBgra(rgba: [4]u8) [4]u8 {
    // readable swizzling by destructuring
    const r, const g, const b, const a = rgba;
    return .{ b, g, r, a };
}

pub fn main() void {
    const pos = [_]i32{ 1, 2 };
    const x, const y = pos;
    print("x = {}, y = {}\n", .{x, y});

    const orange: [4]u8 = .{ 255, 165, 0, 255 };
    print("{any}\n", .{swizzleRgbaToBgra(orange)});
}

// exe=succeed