I’m fairly new to Zig so I might be missing something obvious.
But in any case, I have the following error but I’m not sure what to make of it:
~/src/main.zig:82:39: error: expected type '*mem.Allocator', found '*const mem.Allocator'
var conv = try Converter.init(&arena.allocator(), std.io.getStdOut().writer(), bufSize);
^~~~~~~~~~~~~~~~~~
~/src/main.zig:82:39: note: cast discards const qualifier
referenced by:
comptime_0: /usr/local/Cellar/zig/0.10.1/lib/zig/std/start.zig:59:50
remaining reference traces hidden; use '-freference-trace' to see all reference traces
And the code that generates it:
// in main.zig
const std = @import("std");
const Converter = @import("./converter.zig").Converter;
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
var conv = try Converter.init(&arena.allocator(), std.io.getStdOut().writer(), bufSize);
// other operations
}
And in converter.zig
:
const std = @import("std");
pub const Converter = struct {
const BufferedWriter = std.io.BufferedWriter(4096, std.fs.File.Writer);
allocator: *std.mem.Allocator,
csvBuf: []u8,
hdrBuf: []u8,
rowBuf: []u8,
keys: [][]const u8,
out: BufferedWriter,
const Self = @This();
// Initialize the converter.
pub fn init(allocator: *std.mem.Allocator, writer: anytype, rowBufSize: u32) !Self {
var s = Converter{
.allocator = allocator,
.out = std.io.bufferedWriter(writer),
.csvBuf = try allocator.alloc(u8, rowBufSize),
.hdrBuf = try allocator.alloc(u8, rowBufSize),
.rowBuf = try allocator.alloc(u8, rowBufSize),
.keys = undefined,
};
return s;
}
// other methods like `deinit()` etc
What I’d like to understand the point where this const
comes into play.