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 library itself.

toOwnedSlice

The caller owns the returned memory. Capacity is cleared, making deinit() safe but unnecessary to call.

ArrayListReverse.toOwnedSlice
pub fn toOwnedSlice(self: *ArrayListReverse) Error![]u8

File

lib/std/crypto/codecs/asn1/der/ArrayListReverse.zig:72

Code

pub fn toOwnedSlice(self: *ArrayListReverse) Error![]u8 {
    const new_memory = try self.allocator.alloc(u8, self.data.len);
    @memcpy(new_memory, self.data);
    @memset(self.data, undefined);
    self.clearAndFree();
    return new_memory;
}