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 › http › Client › Connection › Plain Private Struct Plain Doc Source Private Struct std.http.Client.Connection.Plain
const Plain = struct Fields Functions File http/Client.zig: 241
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292 const Plain = struct {
connection : Connection ,
fn create (
client : *Client ,
remote_host : HostName ,
port : u16 ,
stream : Io .net .Stream ,
) error {OutOfMemory }!*Plain {
const io = client .io ;
const gpa = client .allocator ;
const alloc_len = allocLen (client , remote_host .bytes .len );
const base = try gpa .alignedAlloc (u8 , .of (Plain ), alloc_len );
errdefer gpa .free (base );
const host_buffer = base [@sizeOf (Plain )..][0 ..remote_host .bytes .len ];
const socket_read_buffer = host_buffer .ptr [host_buffer .len ..][0 ..client .read_buffer_size ];
const socket_write_buffer = socket_read_buffer .ptr [socket_read_buffer .len ..][0 ..client .write_buffer_size ];
assert (base .ptr + alloc_len == socket_write_buffer .ptr + socket_write_buffer .len );
@memcpy (host_buffer , remote_host .bytes );
const plain : *Plain = @ptrCast (base );
plain .* = .{
.connection = .{
.client = client ,
.stream_writer = stream .writer (io , socket_write_buffer ),
.stream_reader = stream .reader (io , socket_read_buffer ),
.pool_node = .{},
.port = port ,
.host_len = @intCast (remote_host .bytes .len ),
.proxied = false ,
.closing = false ,
.protocol = .plain ,
},
};
return plain ;
}
fn destroy (plain : *Plain ) void {
const c = &plain .connection ;
const gpa = c .client .allocator ;
const base : [*]align (@alignOf (Plain )) u8 = @ptrCast (plain );
gpa .free (base [0 ..allocLen (c .client , c .host_len )]);
}
fn allocLen (client : *Client , host_len : usize ) usize {
return @sizeOf (Plain ) + host_len + client .read_buffer_size + client .write_buffer_size ;
}
fn host (plain : *Plain ) HostName {
const base : [*]u8 = @ptrCast (plain );
return .{ .bytes = base [@sizeOf (Plain )..][0 ..plain .connection .host_len ] };
}
}