0.15.1 Reader/Writer

Thanks got it. Maybe hiding dangerous intermediates behind function calls that return underscored members would work in this kind of cases? I just tried replacing in std all usages of interface with _interface, then having methods like:

    // in std.fs.File.Writer
    _interface: std.Io.Writer,

    pub fn interface(w: *Writer) *std.Io.Writer {
        return &w._interface;
    }

    // in std.fs.File.Reader
    _interface: std.Io.Reader,

    pub fn interface(r: *Reader) *std.Io.Reader {
        return &r._interface;
    }

Then this wouldn’t compile:

    var reader = file.reader(buf).interface();

    while (reader.takeDelimiterExclusive('\n')) |line| {

src/Editor.zig|161 col 34| error: expected type '*fs.File.Reader', found '*const fs.File.Reader'

while this would compile and work

    var reader = file.reader(buf);

    while (reader.interface().takeDelimiterExclusive('\n')) |line| {

Just saying… it would be the usual const-related error for which we know the cure.

Or just methods like reader.getInterface(), so that to renaming the field isn’t necessary.

3 Likes