#How to create a slice on a sentinel terminated array

1 messages · Page 1 of 1 (latest)

jagged hull
#

I have the following code:

var context_atom: [32:0]u8 = .{0} ** 32;

c.c_function_that_write_a_null_terminated_string(&context_atom, context_atom.len);

// Is it possible to do the following in a simpler manner?
var context_slice: []u8 = &.{};
context_slice.ptr = &context_atom;
context_slice.len = mem.indexOfSentinel(u8, 0, &context_atom);

grand cipher
#

var context_slice = context_atom[0..mem.indexOfSentinel(u8, 0, &context_atom)];

#

unless i'm misunderstanding