chore: rename functions

This commit updates the function to match the naming conventions used
in Zig, where variables and fields are snake_case, but functions are
camelCase and types are PascalCase.
This commit is contained in:
Jacob Jonsson 2026-03-15 15:04:56 +01:00
parent bd1891521e
commit 1d44645451
Signed by: Jassob
GPG key ID: 7E30B9B047F7202E
3 changed files with 21 additions and 21 deletions

View file

@ -19,7 +19,7 @@ pub const Message = struct {
author: []const u8,
content: []const u8,
pub fn init_owned(
pub fn initOwned(
allocator: std.mem.Allocator,
timestamp: i64,
author: []const u8,
@ -61,12 +61,12 @@ pub const Bot = struct {
allocator: std.mem.Allocator,
// deinit function for backlog messages
fn deinit_backlog_slot(allocator: std.mem.Allocator, item: *const Message) void {
fn deinitBacklogSlot(allocator: std.mem.Allocator, item: *const Message) void {
item.deinit(allocator);
}
// deinit function for outbox messages.
fn deinit_sent_message(allocator: std.mem.Allocator, item: []u8) void {
fn deinitSentMessage(allocator: std.mem.Allocator, item: []u8) void {
allocator.free(item);
}
@ -81,8 +81,8 @@ pub const Bot = struct {
.backlog = undefined,
.outbox = undefined,
};
bot.backlog = .init_with_closure(allocator, &Bot.deinit_backlog_slot);
bot.outbox = .init_with_closure(allocator, &Bot.deinit_sent_message);
bot.backlog = .initWithClosure(allocator, &Bot.deinitBacklogSlot);
bot.outbox = .initWithClosure(allocator, &Bot.deinitSentMessage);
return bot;
}
@ -166,7 +166,7 @@ pub const Bot = struct {
if (backlog.history >= self.backlog.len()) {
return Error.NoMessage;
}
if (self.backlog.get_backwards(backlog.history)) |message| {
if (self.backlog.getBackwards(backlog.history)) |message| {
const quoted_output = try std.fmt.allocPrint(
self.allocator,
"backlog {}: author: \"{s}\", content: \"{s}\"",
@ -190,7 +190,7 @@ pub const Bot = struct {
}
fn previous_message_by_author(self: *Bot, author: []const u8, targets: []const u8) ?*const Message {
var iter = self.backlog.iterate_reverse();
var iter = self.backlog.iterateReverse();
while (iter.prev()) |message| {
if (std.mem.eql(u8, message.author, author) and
std.mem.eql(u8, message.targets, targets))

View file

@ -28,7 +28,7 @@ pub fn Buffer(comptime T: type, comptime length: usize) type {
};
}
pub fn init_with_closure(
pub fn initWithClosure(
allocator: std.mem.Allocator,
deinit_func: *const fn (allocator: std.mem.Allocator, item: T) void,
) Buffer(T, length) {
@ -38,12 +38,12 @@ pub fn Buffer(comptime T: type, comptime length: usize) type {
return buf;
}
fn can_deinit(self: *const Buffer(T, length)) bool {
fn canDeinit(self: *const Buffer(T, length)) bool {
return self.allocator != null and self.deinit_func != null;
}
fn deinit_item(self: *Buffer(T, length), item: T) void {
if (!self.can_deinit()) {
fn deinitItem(self: *Buffer(T, length), item: T) void {
if (!self.canDeinit()) {
// Nothing to do
return;
}
@ -71,7 +71,7 @@ pub fn Buffer(comptime T: type, comptime length: usize) type {
}
if (self.insertions >= length) {
// free old bottom item
self.deinit_item(self.items[self.top].?);
self.deinitItem(self.items[self.top].?);
self.items[self.top] = null;
}
self.items[self.top] = item;
@ -97,7 +97,7 @@ pub fn Buffer(comptime T: type, comptime length: usize) type {
return self.items[idx];
}
pub fn get_backwards(self: *const Buffer(T, length), offset: usize) ?T {
pub fn getBackwards(self: *const Buffer(T, length), offset: usize) ?T {
if (offset >= self.insertions) {
return null;
}
@ -112,7 +112,7 @@ pub fn Buffer(comptime T: type, comptime length: usize) type {
};
}
pub fn iterate_reverse(self: *const Buffer(T, length)) BufferIterator(T, length) {
pub fn iterateReverse(self: *const Buffer(T, length)) BufferIterator(T, length) {
return .{
.buffer = self,
.index = self.top,
@ -121,12 +121,12 @@ pub fn Buffer(comptime T: type, comptime length: usize) type {
}
pub fn deinit(self: *Buffer(T, length)) void {
if (!self.can_deinit()) {
if (!self.canDeinit()) {
return;
}
for (self.items, 0..) |item, idx| {
if (item != null) {
self.deinit_item(item.?);
self.deinitItem(item.?);
self.items[idx] = null;
}
}
@ -237,7 +237,7 @@ test "deiniting allocating buffer does not leak" {
const allocator = std.testing.allocator;
// create buffer with closure
var buffer = Buffer([]u8, 3).init_with_closure(allocator, &deinit_byte_slice);
var buffer = Buffer([]u8, 3).initWithClosure(allocator, &deinit_byte_slice);
defer buffer.deinit();
// add less elements than length
@ -253,7 +253,7 @@ test "wrapping allocating buffer does not leak" {
const allocator = std.testing.allocator;
// create buffer with closure
var buffer = Buffer([]u8, 3).init_with_closure(allocator, &deinit_byte_slice);
var buffer = Buffer([]u8, 3).initWithClosure(allocator, &deinit_byte_slice);
defer buffer.deinit();
// add an element more than length

View file

@ -76,13 +76,13 @@ pub const BotAdapter = struct {
nick,
msg.targets,
msg.text,
) catch |err| return report_error(err);
) catch |err| return reportError(err);
// send message to bot
const response = self.bot.hear(bot_message) orelse {
return null;
} catch |err| {
return report_error(err);
return reportError(err);
};
return toIRC(response);
},
@ -97,7 +97,7 @@ pub const BotAdapter = struct {
}
}
fn report_error(err: Error) zircon.Message {
fn reportError(err: Error) zircon.Message {
const err_msg = switch (err) {
Error.NoMessage => "no matching message",
Error.OutOfMemory => "out of memory",