From 4a44b7993573016fb5ccb3398d366a884307bf3a Mon Sep 17 00:00:00 2001 From: "Pascal S. de Kloe" Date: Tue, 12 Sep 2023 23:24:26 +0200 Subject: [PATCH] mem: explicit Allocator.Error on concat and join --- lib/std/mem.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 0b6306f1ed..7fd02e8232 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -2948,18 +2948,18 @@ pub fn SplitBackwardsIterator(comptime T: type, comptime delimiter_type: Delimit /// Naively combines a series of slices with a separator. /// Allocates memory for the result, which must be freed by the caller. -pub fn join(allocator: Allocator, separator: []const u8, slices: []const []const u8) ![]u8 { +pub fn join(allocator: Allocator, separator: []const u8, slices: []const []const u8) Allocator.Error![]u8 { return joinMaybeZ(allocator, separator, slices, false); } /// Naively combines a series of slices with a separator and null terminator. /// Allocates memory for the result, which must be freed by the caller. -pub fn joinZ(allocator: Allocator, separator: []const u8, slices: []const []const u8) ![:0]u8 { +pub fn joinZ(allocator: Allocator, separator: []const u8, slices: []const []const u8) Allocator.Error![:0]u8 { const out = try joinMaybeZ(allocator, separator, slices, true); return out[0 .. out.len - 1 :0]; } -fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []const u8, zero: bool) ![]u8 { +fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []const u8, zero: bool) Allocator.Error![]u8 { if (slices.len == 0) return if (zero) try allocator.dupe(u8, &[1]u8{0}) else &[0]u8{}; const total_len = blk: { @@ -3038,18 +3038,18 @@ test "joinZ" { } /// Copies each T from slices into a new slice that exactly holds all the elements. -pub fn concat(allocator: Allocator, comptime T: type, slices: []const []const T) ![]T { +pub fn concat(allocator: Allocator, comptime T: type, slices: []const []const T) Allocator.Error![]T { return concatMaybeSentinel(allocator, T, slices, null); } /// Copies each T from slices into a new slice that exactly holds all the elements. -pub fn concatWithSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: T) ![:s]T { +pub fn concatWithSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: T) Allocator.Error![:s]T { const ret = try concatMaybeSentinel(allocator, T, slices, s); return ret[0 .. ret.len - 1 :s]; } /// Copies each T from slices into a new slice that exactly holds all the elements as well as the sentinel. -pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: ?T) ![]T { +pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: ?T) Allocator.Error![]T { if (slices.len == 0) return if (s) |sentinel| try allocator.dupe(T, &[1]T{sentinel}) else &[0]T{}; const total_len = blk: {