slice_data_cast

This commit is contained in:
gingerBill
2019-07-09 11:09:46 +01:00
parent 7c99f52187
commit 927d6814f2
+10
View File
@@ -129,6 +129,16 @@ slice_to_bytes :: inline proc "contextless" (slice: $E/[]$T) -> []byte {
return transmute([]byte)s;
}
slice_data_cast :: inline proc "contextless" ($T: typeid/[]$A, slice: $S/[]$B) -> T {
when size_of(A) == 0 || size_of(B) == 0 {
return nil;
} else {
s := transmute(Raw_Slice)slice;
s.len = (len(slice) * size_of(B)) / size_of(A);
return transmute(T)s;
}
}
buffer_from_slice :: inline proc(backing: $T/[]$E) -> [dynamic]E {
s := transmute(Raw_Slice)backing;