Class
All Class automatically have the following API
Note
new
pub fn new(ally: std.mem.Allocator) !*Self
Function: Create an object on the heap
parameter:
ally
: memory allocator
Returns: If successful, return the created object, otherwise std.heap.Allocator.Error
make
pub fn make() Self
Function: Create an object on the stack
Returns: the created object
Note
Objects created with make() must call initMixin() before they can be used normally
initMixin
pub fn initMixin(self: *Self) void
Function: Initialize self.mixin
parameter:
self
: target object
destroy
pub fn destroy(self: *Self) void
Function: Destroy object
parameter:
self
: target object
Note
Regardless of whether the object is allocated on the heap or on the stack, you need to call destroy() (unless it is allocated on the heap and it is confirmed that you do not need to call deinit()
), because destroy() is responsible for calling all deinit()
of the object and its parent class
as
pub fn as(self: *const Self, comptime T: type) t: {
break :t if (isInterface(T)) ?T else ?*T;
}
Function: Dynamically convert object types
parameter:
Return: If the conversion is possible, return the converted object or interface, otherwise return null
Note
This conversion requires an array search operation, which is expensive.
cast
pub fn cast(self: *const Self, comptime T: type) t: {
break :t if (isInterface(T)) T else *T;
}
Function: static conversion of object type
parameter:
Return: If the conversion is possible, the converted object or interface is returned, otherwise a compilation error occurs
Note
This conversion has almost no overhead, at most one pointer addition.
asptr
pub fn asptr(self: *const Self) *anyopaque