Convert [*]u8 to []u8 in Zig

Viewed 157

When I have a [*]u8 pointer and a usize length, how do I convert the pointer to a []u8 slice with the specified length?

1 Answers

Use the slice syntax on the [*]u8 pointer:

fn to_slice(pointer: [*]u8, len: usize) []u8 {
    return pointer[0..len];
}
Related