zig/doc/langref/destructuring_arrays.zig

19 lines
447 B
Zig

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