Skip to content

FixedBufferStream needs to declare Error in order to be wrapped with other Readers #22664

@yarrumretep

Description

@yarrumretep

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

Still getting my bearings, but I believe this warrants a bug report. The FixedBufferStream module declares various error unions, but doesn't declare one called Error which is required to use it with wrapping Readers and Writers such as BufferedReader/Writer or CountingReader.

For instance, this code fails to compile:

test "counting reader" {
    const buffer = "hello world";
    const reader = std.io.fixedBufferStream(buffer[0..]);
    const counter = std.io.countingReader(reader);
    const read_buffer: [5]u8 = undefined;
    const n = try counter.read(read_buffer);
    try std.testing.expectEqual(n, 5);
}

The error message is

opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/io/counting_reader.zig:11:37: error: struct 'io.fixed_buffer_stream.FixedBufferStream([]const u8)' has no member named 'Error'
opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/io/fixed_buffer_stream.zig:10:12: note: struct declared here

This issue comes up when creating tests where you want to feed static data into a nested Reader/Writer.

Expected Behavior

Ideally, FixedBufferStream would generate an Error union that is dependent on it's ability to generate a writer (based on the const-ness of the buffer) - that seems to be the only case where it generates an error. The other error unions are currently empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions