clone
Create a copy of this list with a new backing store, using the specified allocator.
Function parameters
Parameters
A MultiArrayList stores a list of a struct or tagged union type.
Functions
- MultiArrayList
- A MultiArrayList stores a list of a struct or tagged union type.
Source
Implementation
pub fn clone(self: Self, gpa: Allocator) !Self {
var result = Self{};
errdefer result.deinit(gpa);
try result.ensureTotalCapacity(gpa, self.len);
result.len = self.len;
const self_slice = self.slice();
const result_slice = result.slice();
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
const field = @as(Field, @enumFromInt(i));
@memcpy(result_slice.items(field), self_slice.items(field));
}
}
return result;
}