authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2022-01-12 18:45:36+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-16 01:37:37-05:00
logf19b5ecf4b99652cd385cfdfedfa826260174871
tree653552e92dcce3b36648003a4fb9fa9bcf74dfc9
parent7f41e20802fd8f9eb19c0218f1e2000e2751592a

Slice function of BoundedArray now returns slice based on self pointer

If self pointer is const, the slice is const. Otherwise the slice is mutable.

1 files changed, 3 insertions(+), 3 deletions(-)

lib/std/bounded_array.zig+3-3
...@@ -28,14 +28,14 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type {...@@ -28,14 +28,14 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type {
28 return Self{ .len = len };28 return Self{ .len = len };
29 }29 }
3030
31 /// View the internal array as a mutable slice whose size was previously set.31 /// View the internal array as a slice whose size was previously set.
32 pub fn slice(self: *Self) []T {32 pub fn slice(self: anytype) mem.Span(@TypeOf(&self.buffer)) {
33 return self.buffer[0..self.len];33 return self.buffer[0..self.len];
34 }34 }
3535
36 /// View the internal array as a constant slice whose size was previously set.36 /// View the internal array as a constant slice whose size was previously set.
37 pub fn constSlice(self: *const Self) []const T {37 pub fn constSlice(self: *const Self) []const T {
38 return self.buffer[0..self.len];38 return self.slice();
39 }39 }
4040
41 /// Adjust the slice's length to `len`.41 /// Adjust the slice's length to `len`.