const JoyVector = struct {
const Self = @This();
allocator: Allocator = undefined,
ptr: *T = undefined, //just modified
len: usize,
cap: usize,
fn new(
comptime T: type,
) !Self {
const ptr = try alloc.create(T);
return Self{ .allocator = alloc, .ptr = ptr, .len = 0, .cap = 0 };
}
fn newWithAllocator(comptime T: type, allocator: Allocator) !Self {
const ptr = try allocator.create(T);
return Self{ .allocator = allocator, .ptr = ptr, .len = 0, .cap = 0 };
}
fn newFromSlice(comptime T: type, slice: []T) !Self {
const len = slice.len;
const cap = len;
const ptr = try alloc.alloc(T, len);
const rptr = ptr.ptr;
std.mem.copyForwards(T, rptr, slice);
return Self{
.allocator = alloc,
.ptr = rptr,
.len = len,
.cap = cap,
};
}
fn newFromSliceWithAllocator(comptime T: type, allocator: Allocator, slice: []T) !Self {
const len = slice.len;
const ptr = try allocator.alloc(T, len);
const rptr = ptr.ptr;
std.mem.copyForwards(T, rptr, slice);
return Self{
.allocator = allocator,
.ptr = rptr,
.len = len,
.cap = len,
};
}
};