Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › crypto › tls › array Public Function array Doc Source Public Function std.crypto.tls.array
pub fn array (
comptime Len : type ,
comptime Elem : type ,
elems : anytype ,
) [@divExact (@bitSizeOf (Len ), 8 ) + @divExact (@bitSizeOf (Elem ), 8 ) * elems .len ]u8 Params Len : type Elem : type elems File crypto/tls.zig: 601
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624 pub fn array (
comptime Len : type ,
comptime Elem : type ,
elems : anytype ,
) [@divExact (@bitSizeOf (Len ), 8 ) + @divExact (@bitSizeOf (Elem ), 8 ) * elems .len ]u8 {
const len_size = @divExact (@bitSizeOf (Len ), 8 );
const elem_size = @divExact (@bitSizeOf (Elem ), 8 );
var arr : [len_size + elem_size * elems .len ]u8 = undefined ;
std .mem .writeInt (Len , arr [0 ..len_size ], @intCast (elem_size * elems .len ), .big );
const ElemInt = @Int (.unsigned , @bitSizeOf (Elem ));
for (0 .., @as ([elems .len ]Elem , elems )) |index , elem | {
std .mem .writeInt (
ElemInt ,
arr [len_size + elem_size * index ..][0 ..elem_size ],
switch (@typeInfo (Elem )) {
.int => @as (Elem , elem ),
.@"enum" => @backingInt (@as (Elem , elem )),
else => @bitCast (@as (Elem , elem )),
},
.big ,
);
}
return arr ;
}