1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

arrays: move carray_to_varray from builtin, make it generic (#15503)

This commit is contained in:
Larpon
2022-08-23 10:12:50 +02:00
committed by GitHub
parent 2dde7ff5ba
commit 9dd8228f91
4 changed files with 31 additions and 12 deletions

View File

@@ -570,3 +570,12 @@ fn can_copy_bits<T>() bool {
}
return false
}
// carray_to_varray copies a C byte array into a V array of type `T`.
// See also: `cstring_to_vstring`
[unsafe]
pub fn carray_to_varray<T>(c_array voidptr, c_array_len int) []T {
mut v_array := []T{len: c_array_len}
unsafe { vmemcpy(v_array.data, c_array, c_array_len * int(sizeof(T))) }
return v_array
}