mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
arrays: move carray_to_varray from builtin, make it generic (#15503)
This commit is contained in:
parent
2dde7ff5ba
commit
9dd8228f91
4 changed files with 31 additions and 12 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue