mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
23 lines
415 B
Zig
23 lines
415 B
Zig
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
|
|
test "@This()" {
|
|
var items = [_]i32{ 1, 2, 3, 4 };
|
|
const list = List(i32){ .items = items[0..] };
|
|
try expect(list.length() == 4);
|
|
}
|
|
|
|
fn List(comptime T: type) type {
|
|
return struct {
|
|
const Self = @This();
|
|
|
|
items: []T,
|
|
|
|
fn length(self: Self) usize {
|
|
return self.items.len;
|
|
}
|
|
};
|
|
}
|
|
|
|
// test
|