Skip to content

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Aug 30, 2025

Follow-up from #24329.

This patchset is the last in the Writergate series. With this, the purification of std.Io is complete, and it is now an empty vessel, ready to accept the new Io interface.

std.Io.Writer.Allocating & Alignment

This API now has a new field:

alignment: std.mem.Alignment,

This is a runtime-known alignment value. The Allocator API supports this if you use the "raw" function variants.

I tried this out in order to be able to reuse std.Io.Writer.Allocating in a place that needed alignment. It worked out pretty well. So well in fact, that this might be an opportunity to do something similar to std.array_list.Aligned...

Migration Guide

  • std.io -> std.Io
  • std.Io.GenericReader -> std.Io.Reader
  • std.Io.AnyReader -> std.Io.Reader
  • std.leb.readUleb128 -> std.Io.Reader.takeLeb128
  • std.leb.readIleb128 -> std.Io.Reader.takeLeb128

FixedBufferStream (reading)

    var fbs = std.io.fixedBufferStream(data);
    const reader = fbs.reader();

⬇️

    var reader: std.Io.Reader = .fixed(data);

FixedBufferStream (writing)

    var fbs = std.io.fixedBufferStream(buffer);
    const writer = fbs.writer();

⬇️

    var writer: std.Io.Reader = .fixed(buffer);

std.fs.Dir.readFileAlloc

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

Note that the limit has a difference; if it's reached it also returns the error. Also the error has been changed from FileTooBig to StreamTooLong.

std.fs.File.readToEndAlloc

const contents = try file.readToEndAlloc(allocator, 1234);

⬇️

var file_reader = file.reader(&.{});
const contents = try file_reader.interface.allocRemaining(allocator, .limited(1234));

and delete deprecated alias std.io
@andrewrk andrewrk added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. standard library This issue involves writing Zig code for the standard library. release notes This PR should be mentioned in the release notes. labels Aug 30, 2025
@andrewrk andrewrk force-pushed the GenericReader branch 2 times, most recently from 08ec4dd to 0f1a98d Compare August 30, 2025 05:31
@andrewrk andrewrk merged commit b710423 into master Aug 30, 2025
25 of 26 checks passed
@andrewrk andrewrk deleted the GenericReader branch August 30, 2025 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant