authorgravatar for 87334103+axlEscalada@users.noreply.github.comaxel escalada <87334103+axlEscalada@users.noreply.github.com> 2025-01-04 10:45:12-03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-01-04 13:45:12+00:00
logff4f2753e4eb1226c1b18a812ee6ff5ca914fe85
treec15de9209027a5290367e85ca4ba5828b931b05f
parentb4da8eef2a393543e9520c544364689ab482b080
signaturebadge-check Signed by PGP key B5690EEEBB952194

Improve `first()` documentation for split iterators

* remove from doc., add explicit info when panic * match convention for assert documentation, avoiding to use panic here

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

lib/std/mem.zig+6-3
...@@ -2903,9 +2903,10 @@ pub fn WindowIterator(comptime T: type) type {...@@ -2903,9 +2903,10 @@ pub fn WindowIterator(comptime T: type) type {
29032903
2904 const Self = @This();2904 const Self = @This();
29052905
2906 /// Returns a slice of the first window. This never fails.2906 /// Returns a slice of the first window.
2907 /// Call this only to get the first window and then use `next` to get2907 /// Call this only to get the first window and then use `next` to get
2908 /// all subsequent windows.2908 /// all subsequent windows.
2909 /// Asserts that iteration has not begun.
2909 pub fn first(self: *Self) []const T {2910 pub fn first(self: *Self) []const T {
2910 assert(self.index.? == 0);2911 assert(self.index.? == 0);
2911 return self.next().?;2912 return self.next().?;
...@@ -3037,8 +3038,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t...@@ -3037,8 +3038,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t
30373038
3038 const Self = @This();3039 const Self = @This();
30393040
3040 /// Returns a slice of the first field. This never fails.3041 /// Returns a slice of the first field.
3041 /// Call this only to get the first field and then use `next` to get all subsequent fields.3042 /// Call this only to get the first field and then use `next` to get all subsequent fields.
3043 /// Asserts that iteration has not begun.
3042 pub fn first(self: *Self) []const T {3044 pub fn first(self: *Self) []const T {
3043 assert(self.index.? == 0);3045 assert(self.index.? == 0);
3044 return self.next().?;3046 return self.next().?;
...@@ -3101,8 +3103,9 @@ pub fn SplitBackwardsIterator(comptime T: type, comptime delimiter_type: Delimit...@@ -3101,8 +3103,9 @@ pub fn SplitBackwardsIterator(comptime T: type, comptime delimiter_type: Delimit
31013103
3102 const Self = @This();3104 const Self = @This();
31033105
3104 /// Returns a slice of the first field. This never fails.3106 /// Returns a slice of the first field.
3105 /// Call this only to get the first field and then use `next` to get all subsequent fields.3107 /// Call this only to get the first field and then use `next` to get all subsequent fields.
3108 /// Asserts that iteration has not begun.
3106 pub fn first(self: *Self) []const T {3109 pub fn first(self: *Self) []const T {
3107 assert(self.index.? == self.buffer.len);3110 assert(self.index.? == self.buffer.len);
3108 return self.next().?;3111 return self.next().?;