rename setToDefault to init

This commit is contained in:
David Mo
2025-02-25 10:15:58 -05:00
parent 22d99f2533
commit af2d710000
2 changed files with 7 additions and 7 deletions

View File

@ -262,8 +262,8 @@ pub fn parseIntoField(
if (value) |v| default: {
if (v.len != 0) break :default;
// Set default value if possible.
if (canHaveDecls and @hasDecl(Field, "setToDefault")) {
try @field(dst, field.name).setToDefault(alloc);
if (canHaveDecls and @hasDecl(Field, "init")) {
try @field(dst, field.name).init(alloc);
return;
}
const raw = field.default_value orelse break :default;
@ -767,7 +767,7 @@ test "parseIntoField: ignore underscore-prefixed fields" {
try testing.expectEqualStrings("12", data._a);
}
test "parseIntoField: struct with default func" {
test "parseIntoField: struct with init func" {
const testing = std.testing;
var arena = ArenaAllocator.init(testing.allocator);
defer arena.deinit();
@ -779,7 +779,7 @@ test "parseIntoField: struct with default func" {
v: []const u8,
pub fn setToDefault(self: *Self, _alloc: Allocator) !void {
pub fn init(self: *Self, _alloc: Allocator) !void {
_ = _alloc;
self.v = "HELLO!";
}

View File

@ -2373,7 +2373,7 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
const alloc = result._arena.?.allocator();
// Add our default keybindings
try result.keybind.setToDefault(alloc);
try result.keybind.init(alloc);
// Add our default link for URL detection
try result.link.links.append(alloc, .{
@ -4492,7 +4492,7 @@ pub const RepeatableFontVariation = struct {
pub const Keybinds = struct {
set: inputpkg.Binding.Set = .{},
pub fn setToDefault(self: *Keybinds, alloc: Allocator) !void {
pub fn init(self: *Keybinds, alloc: Allocator) !void {
// We don't clear the memory because it's in the arena and unlikely
// to be free-able anyways (since arenas can only clear the last
// allocated value). This isn't a memory leak because the arena
@ -5131,7 +5131,7 @@ pub const Keybinds = struct {
// Check for special values
if (value.len == 0) {
log.info("config has 'keybind =', using default keybinds", .{});
try self.setToDefault(alloc);
try self.init(alloc);
return;
}