What am I doing wrong in this example? In deinit()
I am getting an error that expected is *MemoryPool
but *const MemoryPool
was given.
const Tree = struct {
node_pool: std.heap.MemoryPool(Node),
pub fn init(allocator: Allocator) Tree {
var node_pool = std.heap.MemoryPool(Node).init(allocator);
return Tree{ .node_pool = node_pool };
}
pub fn deinit(self: Tree) void {
self.node_pool.deinit(); // <-- error: * is expected, *const is given
}
};
I'm working around the error with @constCast()
but this feels strange - I don't fully understand why I'm doing this and I assume I might be doing something very much wrong. Is there a way to avoid it? Am I missing something?
const Tree = struct {
...
pub fn deinit(self: Tree) void {
@constCast(&self.node_pool).deinit();
}
};