Merge pull request #189 from jetzig-framework/zig-alignment-changes

Use Alignment arg instead of integer
This commit is contained in:
bobf 2025-04-19 19:57:34 +01:00 committed by GitHub
commit 6d9fa8bff4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 23 additions and 17 deletions

View File

@ -447,7 +447,7 @@ fn generateMarkdownFragments(b: *std.Build) ![]const u8 {
}
};
const stat = try file.stat();
const source = try file.readToEndAllocOptions(b.allocator, @intCast(stat.size), null, @alignOf(u8), 0);
const source = try file.readToEndAllocOptions(b.allocator, @intCast(stat.size), null, .of(u8), 0);
if (try getMarkdownFragmentsSource(b.allocator, source)) |markdown_fragments_source| {
return try std.fmt.allocPrint(b.allocator,
\\const std = @import("std");

View File

@ -2,7 +2,7 @@
.name = .jetzig,
.version = "0.0.0",
.fingerprint = 0x93ad8bfa2d209022,
.minimum_zig_version = "0.15.0-dev.345+ec2888858",
.minimum_zig_version = "0.15.0-dev.355+206bd1ced",
.dependencies = .{
.jetcommon = .{
.url = "https://github.com/jetzig-framework/jetcommon/archive/fb4edc13759d87bfcd9b1f5fcefdf93f8c9c62dd.tar.gz",

View File

@ -376,7 +376,7 @@ fn generateRoutesForView(self: *Routes, dir: std.fs.Dir, path: []const u8) !Rout
path,
@intCast(stat.size),
null,
@alignOf(u8),
.of(u8),
0,
);
defer self.allocator.free(source);

View File

@ -33,7 +33,7 @@ pub fn main() !void {
const Repo = jetzig.jetquery.Repo(jetzig.database.adapter, Schema);
var repo = try Repo.loadConfig(
allocator,
std.enums.nameCast(jetzig.jetquery.Environment, jetzig.environment),
@field(jetzig.jetquery.Environment, @tagName(jetzig.environment)),
.{ .env = try jetzig.database.repoEnv(env), .context = .cli },
);
defer repo.deinit();
@ -60,7 +60,7 @@ pub fn main() !void {
const email = args[2];
try repo.insert(std.enums.nameCast(std.meta.DeclEnum(Schema), model), .{
try repo.insert(@field(std.meta.DeclEnum(Schema), model), .{
.email = email,
.password_hash = try hashPassword(allocator, password),
});

View File

@ -133,7 +133,7 @@ const MigrationsRepo = jetquery.Repo(config.adapter, MigrateSchema);
fn migrationsRepo(action: Action, allocator: std.mem.Allocator, repo_env: anytype) !MigrationsRepo {
return try MigrationsRepo.loadConfig(
allocator,
std.enums.nameCast(jetquery.Environment, environment),
@field(jetquery.Environment, @tagName(environment)),
.{
.admin = switch (action) {
.migrate, .rollback, .update => false,
@ -154,7 +154,7 @@ fn reflectSchema(allocator: std.mem.Allocator, repo_env: anytype) !void {
const Repo = jetquery.Repo(config.adapter, Schema);
var repo = try Repo.loadConfig(
allocator,
std.enums.nameCast(jetquery.Environment, environment),
@field(jetquery.Environment, @tagName(environment)),
.{ .context = .migration, .env = repo_env },
);
const reflect = @import("jetquery_reflect").Reflect(config.adapter, Schema).init(

View File

@ -33,7 +33,10 @@ pub const Date = jetcommon.types.Date;
pub const authenticity_token_name = config.get([]const u8, "authenticity_token_name");
pub const build_options = @import("build_options");
pub const environment = std.enums.nameCast(Environment.EnvironmentName, build_options.environment);
pub const environment = @field(
Environment.EnvironmentName,
@tagName(build_options.environment),
);
/// The primary interface for a Jetzig application. Create an `App` in your application's
/// `src/main.zig` and call `start` to launch the application.

View File

@ -14,7 +14,7 @@ pub fn getUserId(comptime id_type: IdType, request: *jetzig.Request) !?switch (i
} {
const session = try request.session();
return session.getT(std.enums.nameCast(jetzig.data.ValueType, id_type), "_jetzig_user_id");
return session.getT(@field(jetzig.data.ValueType, id_type), "_jetzig_user_id");
}
pub fn signIn(request: *jetzig.Request, user_id: anytype) !void {

View File

@ -18,7 +18,10 @@ pub const mail = @import("mail.zig");
pub const kv = @import("kv.zig");
pub const db = @import("database.zig");
pub const Environment = @import("Environment.zig");
pub const environment = std.enums.nameCast(Environment.EnvironmentName, build_options.environment);
pub const environment = @field(
Environment.EnvironmentName,
@tagName(build_options.environment),
);
pub const build_options = @import("build_options");
const root = @import("root");

View File

@ -2,9 +2,9 @@ const std = @import("std");
const jetzig = @import("../jetzig.zig");
pub const adapter = std.enums.nameCast(
pub const adapter = @field(
jetzig.jetquery.adapters.Name,
@field(jetzig.jetquery.config.database, @tagName(jetzig.environment)).adapter,
@tagName(@field(jetzig.jetquery.config.database, @tagName(jetzig.environment)).adapter),
);
pub const Schema = jetzig.config.get(type, "Schema");
@ -25,7 +25,7 @@ pub fn repo(allocator: std.mem.Allocator, app: anytype) !Repo {
return try Repo.loadConfig(
allocator,
std.enums.nameCast(jetzig.jetquery.Environment, jetzig.environment),
@field(jetzig.jetquery.Environment, @tagName(jetzig.environment)),
.{
.eventCallback = Callback.callbackFn,
.lazy_connect = switch (jetzig.environment) {

View File

@ -41,9 +41,9 @@ fn jetKVOptions(options: KVOptions) jetzig.jetkv.Options {
.port = options.valkey_options.port,
.connect_timeout = options.valkey_options.connect_timeout * std.time.ms_per_s,
.read_timeout = options.valkey_options.read_timeout * std.time.ms_per_s,
.connect = std.enums.nameCast(
.connect = @field(
jetzig.jetkv.ValkeyBackendOptions.ConnectMode,
options.valkey_options.connect,
@tagName(options.valkey_options.connect),
),
.buffer_size = options.valkey_options.buffer_size,
.pool_size = options.valkey_options.pool_size,

View File

@ -50,7 +50,7 @@ fn detectEncoding(request: *const jetzig.http.Request) ?Encoding {
while (it.next()) |param| {
inline for (@typeInfo(Encoding).@"enum".fields) |field| {
if (std.mem.eql(u8, field.name, jetzig.util.strip(param))) {
return std.enums.nameCast(Encoding, field.name);
return @field(Encoding, field.name);
}
}
}

View File

@ -347,7 +347,7 @@ fn stubbedRequest(
.route_data = null,
.middlewares = undefined,
.address = undefined,
.method = std.enums.nameCast(httpz.Method, @tagName(method)),
.method = @field(httpz.Method, @tagName(method)),
.protocol = .HTTP11,
.params = undefined,
.conn = undefined,