aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_list.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-04-01 11:56:39 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-04-01 11:56:39 -0400
commit553f0e0546e0ceecf2ff735443d9a2c2f282b8db (patch)
tree42257c00a7315bc9eb531718390050deffa4022e /lib/std/array_list.zig
parent7eb938c9096db54fe6e99148824252904c79c227 (diff)
downloadzig-553f0e0546e0ceecf2ff735443d9a2c2f282b8db.tar.gz
zig-553f0e0546e0ceecf2ff735443d9a2c2f282b8db.zip
fixups and revert a few things
Diffstat (limited to 'lib/std/array_list.zig')
-rw-r--r--lib/std/array_list.zig36
1 files changed, 17 insertions, 19 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 87bf3c51df..523d1c810f 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -189,32 +189,30 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
self.len += items.len;
}
- pub usingnamespace if (T == u8)
- struct {
- /// Same as `append` except it returns the number of bytes written, which is always the same
- /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API.
- fn appendWrite(self: *Self, m: []const u8) !usize {
- try self.appendSlice(m);
- return m.len;
- }
-
- pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) {
- return .{ .context = self };
- }
- }
- else
- struct {};
+ /// Same as `append` except it returns the number of bytes written, which is always the same
+ /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API.
+ /// This function may be called only when `T` is `u8`.
+ fn appendWrite(self: *Self, m: []const u8) !usize {
+ try self.appendSlice(m);
+ return m.len;
+ }
+
+ /// Initializes an OutStream which will append to the list.
+ /// This function may be called only when `T` is `u8`.
+ pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) {
+ return .{ .context = self };
+ }
- /// Append a value to the list `n` times. Allocates more memory
- /// as necessary.
+ /// Append a value to the list `n` times.
+ /// Allocates more memory as necessary.
pub fn appendNTimes(self: *Self, value: T, n: usize) !void {
const old_len = self.len;
try self.resize(self.len + n);
mem.set(T, self.items[old_len..self.len], value);
}
- /// Adjust the list's length to `new_len`. Doesn't initialize
- /// added items if any.
+ /// Adjust the list's length to `new_len`.
+ /// Does not initialize added items if any.
pub fn resize(self: *Self, new_len: usize) !void {
try self.ensureCapacity(new_len);
self.len = new_len;