std: LinearFifo matches ArrayList in always having outStream method

This commit is contained in:
daurnimator 2020-04-02 20:55:59 +11:00
parent f6d384450f
commit 2a031c8825
No known key found for this signature in database
GPG Key ID: 45B429A8F9D9D22A

View File

@ -291,24 +291,16 @@ pub fn LinearFifo(
return self.writeAssumeCapacity(src);
}
pub usingnamespace if (T == u8)
struct {
const OutStream = std.io.OutStream(*Self, Error, appendWrite);
const Error = error{OutOfMemory};
/// Same as `write` except it returns the number of bytes written, which is always the same
/// as `bytes.len`. The purpose of this function existing is to match `std.io.OutStream` API.
fn appendWrite(self: *Self, bytes: []const u8) error{OutOfMemory}!usize {
try self.write(bytes);
return bytes.len;
}
/// Same as `write` except it returns the number of bytes written, which is always the same
/// as `bytes.len`. The purpose of this function existing is to match `std.io.OutStream` API.
pub fn appendWrite(fifo: *Self, bytes: []const u8) Error!usize {
try fifo.write(bytes);
return bytes.len;
}
pub fn outStream(self: *Self) OutStream {
return .{ .context = self };
}
}
else
struct {};
pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) {
return .{ .context = self };
}
/// Make `count` items available before the current read location
fn rewind(self: *Self, count: usize) void {