Skip to content

std.Io: delete GenericReader, AnyReader, FixedBufferStream; and related API breakage - #25077

Merged
andrewrk merged 6 commits into
masterfrom
GenericReader
Aug 30, 2025
Merged

std.Io: delete GenericReader, AnyReader, FixedBufferStream; and related API breakage#25077
andrewrk merged 6 commits into
masterfrom
GenericReader

Conversation

@andrewrk

@andrewrkandrewrk commented Aug 30, 2025

Copy link
Copy Markdown
Member

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)

varfbs=std.io.fixedBufferStream(data);
constreader=fbs.reader();

⬇️

varreader: std.Io.Reader= .fixed(data);

FixedBufferStream (writing)

varfbs=std.io.fixedBufferStream(buffer);
constwriter=fbs.writer();

⬇️

varwriter: 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

constcontents=tryfile.readToEndAlloc(allocator, 1234);

⬇️

varfile_reader=file.reader(&.{});
constcontents=tryfile_reader.interface.allocRemaining(allocator, .limited(1234));

and delete deprecated alias std.io
@andrewrkandrewrk 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
andrewrkforce-pushed the GenericReader branch 2 times, most recently from 08ec4dd to 0f1a98dCompareAugust 30, 2025 05:31
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breakingImplementing this issue could cause existing code to no longer compile or have different behavior.release notesThis PR should be mentioned in the release notes.standard libraryThis issue involves writing Zig code for the standard library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@andrewrk