I apologize if I am asking a trivial question but what is an idiomatic way to cast (convert) a sentinel terminated array of the type [*:0]u8
to a slice []const u8
?
Takes a sentinel-terminated pointer and returns a slice, iterating over the memory to find the sentinel and determine the length. Pointer attributes such as const are preserved.
[*c]
pointers are assumed to be non-null and 0-terminated.
10 Likes
Thank you! This is exactly what I was looking for.
for null-terminated character arrays,
std.mem.sliceTo(data[0..], 0)
could be another option.