Convert []const u8 to [*:0]const u8

Hello @jjuel, welcome to the forum.

Types:

  • [*:0]const u8 is a sentinel terminated pointer, a pointer to 0 terminated string of u8.
  • []const u8 is a slice, a pointer and a length.
  • [:0]const u8 is a 0 terminated sentinel slice, a pointer to 0 terminated string and a length.

Convertions:

  • 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;
11 Likes