@@ -345,7 +345,7 @@ pub const ID = struct {
345
345
346
346
pub fn generate () Self {
347
347
var rng = std .rand .DefaultPrng .init (
348
- @truncate (u64 , @intCast ( u128 , std .time .nanoTimestamp ())),
348
+ @as (u64 , @truncate ( @as ( u128 , @intCast ( std .time .nanoTimestamp ()) ))),
349
349
);
350
350
const rand = rng .random ();
351
351
const generated_ulid = ulidFromTimestamp (rand , std .time .milliTimestamp ());
@@ -354,7 +354,7 @@ pub const ID = struct {
354
354
355
355
pub fn generateWithTimestamp (milliTimestamp : anytype ) Self {
356
356
var rng = std .rand .DefaultPrng .init (
357
- @truncate (u64 , @intCast ( u128 , std .time .nanoTimestamp ())),
357
+ @as (u64 , @truncate ( @as ( u128 , @intCast ( std .time .nanoTimestamp ()) ))),
358
358
);
359
359
const rand = rng .random ();
360
360
@@ -442,7 +442,7 @@ pub fn loadDatabase(allocator: std.mem.Allocator, given_options: LoadDatabaseOpt
442
442
options .home_path = home_path ;
443
443
}
444
444
445
- const db_path_cstr = try std . cstr . addNullByte ( allocator , options .db_path .? );
445
+ const db_path_cstr = try allocator . dupeZ ( u8 , options .db_path .? );
446
446
defer allocator .free (db_path_cstr );
447
447
448
448
var diags : sqlite.Diagnostics = undefined ;
@@ -846,7 +846,7 @@ pub const Context = struct {
846
846
/// Caller owns the returned memory.
847
847
fn randomCoreData (self : * Self , core_output : []u8 ) void {
848
848
_ = self ;
849
- const seed = @truncate (u64 , @bitCast ( u128 , std .time .nanoTimestamp ()));
849
+ const seed = @as (u64 , @truncate ( @as ( u128 , @bitCast ( std .time .nanoTimestamp ()) )));
850
850
var r = std .rand .DefaultPrng .init (seed );
851
851
for (core_output , 0.. ) | _ , index | {
852
852
var random_byte = r .random ().uintAtMost (u8 , 255 );
@@ -925,10 +925,7 @@ pub const Context = struct {
925
925
926
926
if (tag_name_regex ) | tag_name_regex_string | {
927
927
defer self .allocator .free (tag_name_regex_string );
928
- self .library_config .tag_name_regex_string = try std .cstr .addNullByte (
929
- self .allocator ,
930
- tag_name_regex_string ,
931
- );
928
+ self .library_config .tag_name_regex_string = try self .allocator .dupeZ (u8 , tag_name_regex_string );
932
929
933
930
self .library_config .tag_name_regex = try libpcre .Regex .compile (
934
931
self .library_config .tag_name_regex_string .? ,
@@ -941,7 +938,7 @@ pub const Context = struct {
941
938
pub fn updateLibraryConfig (self : * Self , field : LibraryConfiguration.FieldUpdateRequest ) ! void {
942
939
switch (field ) {
943
940
.tag_name_regex = > | new_regex | {
944
- const new_regex_cstr = try std . cstr . addNullByte ( self .allocator , new_regex );
941
+ const new_regex_cstr = try self .allocator . dupeZ ( u8 , new_regex );
945
942
defer self .allocator .free (new_regex_cstr );
946
943
const regex = libpcre .Regex .compile (new_regex_cstr , DefaultRegexOptions ) catch | err | {
947
944
logger .err ("failed to compile regex: {s}" , .{@errorName (err )});
@@ -1072,7 +1069,7 @@ pub const Context = struct {
1072
1069
if (options .source ) | source | {
1073
1070
if (options .parent_source_id ) | parent_source_id | {
1074
1071
if (source .kind != TagSourceType .system ) return error .InvalidSourceType ;
1075
- if (source .id != @enumToInt (SystemTagSources .tag_parenting )) {
1072
+ if (source .id != @intFromEnum (SystemTagSources .tag_parenting )) {
1076
1073
logger .err ("expected tag parent source, got {}" , .{source });
1077
1074
return error .InvalidSourceID ;
1078
1075
}
@@ -1082,15 +1079,15 @@ pub const Context = struct {
1082
1079
\\values (?, ?, ?, ?, ?) on conflict do nothing
1083
1080
,
1084
1081
.{},
1085
- .{ core_hash .id .sql (), self .hash .id .sql (), @enumToInt (source .kind ), source .id , parent_source_id },
1082
+ .{ core_hash .id .sql (), self .hash .id .sql (), @intFromEnum (source .kind ), source .id , parent_source_id },
1086
1083
);
1087
1084
} else {
1088
1085
try self .ctx .db .exec (
1089
1086
\\insert into tag_files (core_hash, file_hash, tag_source_type, tag_source_id)
1090
1087
\\values (?, ?, ?, ?) on conflict do nothing
1091
1088
,
1092
1089
.{},
1093
- .{ core_hash .id .sql (), self .hash .id .sql (), @enumToInt (source .kind ), source .id },
1090
+ .{ core_hash .id .sql (), self .hash .id .sql (), @intFromEnum (source .kind ), source .id },
1094
1091
);
1095
1092
}
1096
1093
} else {
@@ -1159,7 +1156,7 @@ pub const Context = struct {
1159
1156
try self .ctx .db .exec (
1160
1157
"delete from tag_sources where type = ? and id = ?" ,
1161
1158
.{},
1162
- .{ @enumToInt (TagSourceType .external ), self .id },
1159
+ .{ @intFromEnum (TagSourceType .external ), self .id },
1163
1160
);
1164
1161
}
1165
1162
};
@@ -1208,7 +1205,7 @@ pub const Context = struct {
1208
1205
.core = hash_with_blob .toRealHash (),
1209
1206
.source = Source {
1210
1207
.ctx = self .ctx ,
1211
- .kind = @intToEnum (TagSourceType , row .tag_source_type ),
1208
+ .kind = @as (TagSourceType , @enumFromInt ( row .tag_source_type ) ),
1212
1209
.id = row .tag_source_id ,
1213
1210
},
1214
1211
.parent_source_id = row .parent_source_id ,
@@ -1273,7 +1270,7 @@ pub const Context = struct {
1273
1270
try self .db .exec (
1274
1271
"insert into tag_sources (type, id, name) values (?, ?, ?)" ,
1275
1272
.{},
1276
- .{ @enumToInt (TagSourceType .external ), source_id , name },
1273
+ .{ @intFromEnum (TagSourceType .external ), source_id , name },
1277
1274
);
1278
1275
1279
1276
return File.Source { .ctx = self , .kind = .external , .id = source_id };
@@ -1292,7 +1289,7 @@ pub const Context = struct {
1292
1289
struct { type : i64 , id : i64 },
1293
1290
"select type, id from tag_sources where type = ? and id = ?" ,
1294
1291
.{},
1295
- .{ @enumToInt (TagSourceType .external ), id },
1292
+ .{ @intFromEnum (TagSourceType .external ), id },
1296
1293
);
1297
1294
1298
1295
if (maybe_row ) | row | {
@@ -1657,7 +1654,7 @@ pub const Context = struct {
1657
1654
});
1658
1655
1659
1656
try file .addTag (.{ .id = tag_entry .tag_id , .hash_data = undefined }, .{
1660
- .source = try self .fetchTagSource (.system , @enumToInt (SystemTagSources .tag_parenting )),
1657
+ .source = try self .fetchTagSource (.system , @intFromEnum (SystemTagSources .tag_parenting )),
1661
1658
.parent_source_id = tag_entry .parent_entry_id ,
1662
1659
});
1663
1660
}
@@ -1977,7 +1974,7 @@ pub fn log(
1977
1974
comptime format : []const u8 ,
1978
1975
args : anytype ,
1979
1976
) void {
1980
- if (@enumToInt (message_level ) <= @enumToInt (@import ("root" ).current_log_level )) {
1977
+ if (@intFromEnum (message_level ) <= @intFromEnum (@import ("root" ).current_log_level )) {
1981
1978
std .log .defaultLog (message_level , scope , format , args );
1982
1979
}
1983
1980
}
@@ -2371,7 +2368,7 @@ test "tag parenting" {
2371
2368
for (file_tags ) | file_tag | {
2372
2369
if (std .meta .eql (file_tag .core .id , parent_tag .core .id )) {
2373
2370
try std .testing .expectEqual (TagSourceType .system , file_tag .source .kind );
2374
- try std .testing .expectEqual (@as (i64 , @enumToInt (SystemTagSources .tag_parenting )), file_tag .source .id );
2371
+ try std .testing .expectEqual (@as (i64 , @intFromEnum (SystemTagSources .tag_parenting )), file_tag .source .id );
2375
2372
try std .testing .expectEqual (tag_tree_entry_id , file_tag .parent_source_id .? );
2376
2373
saw_parent = true ;
2377
2374
}
0 commit comments