Interface for readFileAlloc changed, can somebody please help me understand why?

In
std.Io: delete GenericReader, AnyReader, FixedBufferStream; and related API breakage by andrewrk · Pull Request #25077 · ziglang/zig · GitHub the interface for readFileAlloc changed so that allocator is now second argument instead of first one

-    const contents = try std.fs.cwd().readFileAlloc(allocator, file_name, 1234);
+    const contents = try std.fs.cwd().readFileAlloc(file_name, allocator, .limited(1234));

Can somebody please help me understand the reasoning behind this? Also is there a zig convention for passing allocator at specific argument position?

I recall some discussion about a conventional position and ordering for io and allocator, but no consensus has emerged.

I speculate that in this particular case, the change is to make the arguments consistent with the function name: read - File - Alloc = filename, allocator, …

2 Likes

Thank you!

I speculate that in this particular case, the change is to make the arguments consistent with the function name: read - File - Alloc = filename, allocator, …

Oh, did not notice that! This makes sense, thanks)

1 Like