4

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

Dull Bananas
  • 892
  • 7
  • 29

1 Answers1

7

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

fn to_slice(pointer: [*]u8, len: usize) []u8 {
    return pointer[0..len];
}
Dull Bananas
  • 892
  • 7
  • 29