You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users only have access to a *Response and Request instance.
This means that if they require access to some allocator, database connection, or w/e, the variable must be global. This is very annoying to work with, and also prone to footguns.
The idea is to allow providing a context variable to the server, which is then accessible within the handler.
Using comptime we can ensure the types match.
This would look as follow:
tryserver.run(
...,
some_variable,
myHandle);
fnmyHandle(ctx: @TypeOf(some_variable), resp: *Response, req: Request) !void {
// access to `some_variable` is possible here.// Allows both constants and mutable pointers, depending on what was provided in the `run` function.
}
The text was updated successfully, but these errors were encountered:
Users only have access to a
*Response
andRequest
instance.This means that if they require access to some allocator, database connection, or w/e, the variable must be global. This is very annoying to work with, and also prone to footguns.
The idea is to allow providing a context variable to the server, which is then accessible within the handler.
Using comptime we can ensure the types match.
This would look as follow:
The text was updated successfully, but these errors were encountered: