mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 23:24:09 +00:00
app cosmetics
This commit is contained in:
parent
d4a2079542
commit
efd26fd3bb
1 changed files with 6 additions and 6 deletions
12
src/App.zig
12
src/App.zig
|
@ -55,24 +55,24 @@ pub fn Create(comptime Context: type) type {
|
||||||
pub fn Wrap(T: type) type {
|
pub fn Wrap(T: type) type {
|
||||||
return struct {
|
return struct {
|
||||||
wrapped: *T,
|
wrapped: *T,
|
||||||
wrapper: Interface,
|
interface: Interface,
|
||||||
opts: Opts,
|
opts: Opts,
|
||||||
app_context: *Context,
|
app_context: *Context,
|
||||||
|
|
||||||
const Wrapped = @This();
|
const Wrapped = @This();
|
||||||
|
|
||||||
pub fn unwrap(wrapper: *Interface) *Wrapped {
|
pub fn unwrap(interface: *Interface) *Wrapped {
|
||||||
const self: *Wrapped = @alignCast(@fieldParentPtr("wrapper", wrapper));
|
const self: *Wrapped = @alignCast(@fieldParentPtr("interface", interface));
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(allocator: Allocator, wrapper: *Interface) void {
|
pub fn destroy(allocator: Allocator, wrapper: *Interface) void {
|
||||||
const self: *Wrapped = @alignCast(@fieldParentPtr("wrapper", wrapper));
|
const self: *Wrapped = @alignCast(@fieldParentPtr("interface", wrapper));
|
||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onRequestWrapped(wrapper: *Interface, r: zap.Request) !void {
|
pub fn onRequestWrapped(interface: *Interface, r: zap.Request) !void {
|
||||||
var self: *Wrapped = Wrapped.unwrap(wrapper);
|
var self: *Wrapped = Wrapped.unwrap(interface);
|
||||||
const arena = try get_arena();
|
const arena = try get_arena();
|
||||||
try self.onRequest(arena.allocator(), self.app_context, r);
|
try self.onRequest(arena.allocator(), self.app_context, r);
|
||||||
arena.reset(.{ .retain_capacity = self.opts.arena_retain_capacity });
|
arena.reset(.{ .retain_capacity = self.opts.arena_retain_capacity });
|
||||||
|
|
Loading…
Add table
Reference in a new issue