Adapted from @dimdin’s post: Convert []const u8 to [*:0]const u8 - #2 by dimdin
Slice Types
[*:0]const u8
is a sentinel terminated pointer, a pointer to0
terminated string ofu8
.[]const u8
is a slice, a pointer and a length.[:0]const u8
is a0
terminated sentinel slice, a pointer to0
terminated string and a length.
Conversions
- To convert from a zero terminated pointer to a slice use:
std.mem.span
. - To convert from a
0
terminated sentinel slice to a zero terminated pointer call.ptr
// "Hello" is a zero terminated array of u8
const hello: [:0]const u8 = "Hello";
const ptr: [*:0]const u8 = hello.ptr;
- To convert from a non zero terminated slice to a zero terminated pointer use: std:mem.Allocator.dupeZ