| ... | ... | @@ -58,11 +58,11 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 58 | 58 | |
| 59 | 59 | /// Appends to the `std.ArrayList` contents by reading from the stream until end of stream is found. |
| 60 | 60 | /// If the number of bytes appended would exceed `max_append_size`, `error.StreamTooLong` is returned and the `std.ArrayList` has exactly `max_append_size` bytes appended. |
| 61 | | fn readAllArrayList(self: Self, array_list: *std.ArrayList(u8), max_append_size: usize) !void { |
| 61 | fn readAllArrayList(self: Self, array_list: *std.array_list.Managed(u8), max_append_size: usize) !void { |
| 62 | 62 | return readAllArrayListAligned(self, null, array_list, max_append_size); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | | fn readAllArrayListAligned(self: Self, comptime alignment: ?u29, array_list: *std.ArrayListAligned(u8, alignment), max_append_size: usize) !void { |
| 65 | fn readAllArrayListAligned(self: Self, comptime alignment: ?std.mem.Alignment, array_list: *std.array_list.AlignedManaged(u8, alignment), max_append_size: usize) !void { |
| 66 | 66 | try array_list.ensureTotalCapacity(@min(max_append_size, 4096)); |
| 67 | 67 | const original_len = array_list.items.len; |
| 68 | 68 | var start_index: usize = original_len; |
| ... | ... | @@ -92,7 +92,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 92 | 92 | /// Caller owns returned memory. |
| 93 | 93 | /// If this function returns an error, the contents from the stream read so far are lost. |
| 94 | 94 | pub fn readAllAlloc(self: Self, allocator: std.mem.Allocator, max_size: usize) ![]u8 { |
| 95 | | var array_list = std.ArrayList(u8).init(allocator); |
| 95 | var array_list = std.array_list.Managed(u8).init(allocator); |
| 96 | 96 | defer array_list.deinit(); |
| 97 | 97 | try readAllArrayList(self, &array_list, max_size); |
| 98 | 98 | return try array_list.toOwnedSlice(); |
| ... | ... | @@ -109,7 +109,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /// Returned slice is not suffixed by needle but array_list will contain it. |
| 112 | | pub fn readUntilDelimiterArrayList(self: Self, array_list: *std.ArrayList(u8), needle: u8, max_size: usize) ![]u8 { |
| 112 | pub fn readUntilDelimiterArrayList(self: Self, array_list: *std.array_list.Managed(u8), needle: u8, max_size: usize) ![]u8 { |
| 113 | 113 | const initial_len = array_list.items.len; |
| 114 | 114 | for (0..max_size) |i| { |
| 115 | 115 | try array_list.append(try readByte(self)); |
| ... | ... | @@ -120,14 +120,14 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 120 | 120 | |
| 121 | 121 | /// Returned slice is suffixed by needle. |
| 122 | 122 | pub fn readUntilDelimiterAlloc(self: Self, allocator: std.mem.Allocator, needle: u8, max_size: usize) ![]u8 { |
| 123 | | var list: std.ArrayList(u8) = .init(allocator); |
| 123 | var list: std.array_list.Managed(u8) = .init(allocator); |
| 124 | 124 | errdefer list.deinit(); |
| 125 | 125 | _ = try readUntilDelimiterArrayList(self, &list, needle, max_size); |
| 126 | 126 | return list.toOwnedSlice(); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | pub fn readUntilDelimiterOrEofAlloc(self: Self, allocator: std.mem.Allocator, needle: u8, max_size: usize) !?[]u8 { |
| 130 | | var list: std.ArrayList(u8) = .init(allocator); |
| 130 | var list: std.array_list.Managed(u8) = .init(allocator); |
| 131 | 131 | defer list.deinit(); |
| 132 | 132 | _ = readUntilDelimiterArrayList(self, &list, needle, max_size) catch |err| switch (err) { |
| 133 | 133 | error.EndOfStream => return null, |
| ... | ... | @@ -149,7 +149,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /// Returned slice is not suffixed by needle but array_list will contain it. |
| 152 | | pub fn readUntilDelimitersArrayList(self: Self, array_list: *std.ArrayList(u8), needle: []const u8, max_size: usize) ![]u8 { |
| 152 | pub fn readUntilDelimitersArrayList(self: Self, array_list: *std.array_list.Managed(u8), needle: []const u8, max_size: usize) ![]u8 { |
| 153 | 153 | const initial_len = array_list.items.len; |
| 154 | 154 | for (0..max_size) |i| { |
| 155 | 155 | try array_list.append(try readByte(self)); |
| ... | ... | @@ -159,7 +159,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | pub fn readAlloc(self: Self, allocator: std.mem.Allocator, size: usize) ![]u8 { |
| 162 | | var array_list = try std.ArrayList(u8).initCapacity(allocator, size); |
| 162 | var array_list = try std.array_list.Managed(u8).initCapacity(allocator, size); |
| 163 | 163 | defer array_list.deinit(); |
| 164 | 164 | try array_list.ensureUnusedCapacity(size); |
| 165 | 165 | const len = try readAll(self, array_list.allocatedSlice()); |
| ... | ... | @@ -176,7 +176,7 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 176 | 176 | |
| 177 | 177 | /// Returned slice is suffixed by needle. |
| 178 | 178 | pub fn readUntilDelimitersAlloc(self: Self, allocator: std.mem.Allocator, needle: []const u8, max_size: usize) ![]u8 { |
| 179 | | var list: std.ArrayList(u8) = .init(allocator); |
| 179 | var list: std.array_list.Managed(u8) = .init(allocator); |
| 180 | 180 | errdefer list.deinit(); |
| 181 | 181 | _ = try readUntilDelimitersArrayList(self, &list, needle, max_size); |
| 182 | 182 | return list.toOwnedSlice(); |