From 7884d84315f4080bfe429d3e29f7ebedf9f3f623 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 25 Aug 2021 17:39:30 -0700 Subject: std.os.windows: reorg to avoid `usingnamespace` Down to 19 uses of `usingnamespace`. --- lib/std/array_list.zig | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'lib/std/array_list.zig') diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index f6ee5cdad2..3a66b9bb36 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -236,21 +236,23 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { mem.copy(T, self.items[old_len..], items); } - pub usingnamespace if (T != u8) struct {} else struct { - pub const Writer = std.io.Writer(*Self, error{OutOfMemory}, appendWrite); + pub const Writer = if (T != u8) + @compileError("The Writer interface is only defined for ArrayList(u8) " ++ + "but the given type is ArrayList(" ++ @typeName(T) ++ ")") + else + std.io.Writer(*Self, error{OutOfMemory}, appendWrite); - /// Initializes a Writer which will append to the list. - pub fn writer(self: *Self) Writer { - return .{ .context = self }; - } + /// Initializes a Writer which will append to the list. + pub fn writer(self: *Self) Writer { + return .{ .context = self }; + } - /// 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.Writer` API. - fn appendWrite(self: *Self, m: []const u8) !usize { - try self.appendSlice(m); - return m.len; - } - }; + /// 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.Writer` API. + fn appendWrite(self: *Self, m: []const u8) !usize { + try self.appendSlice(m); + return m.len; + } /// Append a value to the list `n` times. /// Allocates more memory as necessary. -- cgit v1.2.3 From 211856693193b6e5ba4d58bdec1afdb839071fb3 Mon Sep 17 00:00:00 2001 From: Silver Date: Sat, 11 Sep 2021 00:11:51 +0100 Subject: std: publicize ArrayListUnmanaged.allocatedSlice to match ArrayList --- lib/std/array_list.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/std/array_list.zig') diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 3a66b9bb36..5c7b294c5c 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -743,7 +743,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ /// For a nicer API, `items.len` is the length, not the capacity. /// This requires "unsafe" slicing. - fn allocatedSlice(self: Self) Slice { + pub fn allocatedSlice(self: Self) Slice { return self.items.ptr[0..self.capacity]; } }; -- cgit v1.2.3