authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-11-11 02:46:40+11:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-11-25 09:26:33+11:00
log61179a4d5210399107c2964f02071cb55264bba2
tree2a8462e8caebab57ca10ff2df0920db54196d760
parent6037f892125fc87996450f3f985b0d2eb38765c0
signaturelock-open Commit is signed but in an unrecognized format.

std: follow zig standard library convention and have fifo.read number of items


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

lib/std/fifo.zig+5-5
...@@ -203,8 +203,8 @@ pub fn LinearFifo(...@@ -203,8 +203,8 @@ pub fn LinearFifo(
203 return c;203 return c;
204 }204 }
205205
206 /// Read data from the fifo into `dst`, returns slice of bytes copied (subslice of `dst`)206 /// Read data from the fifo into `dst`, returns number of bytes copied.
207 pub fn read(self: *Self, dst: []T) []T {207 pub fn read(self: *Self, dst: []T) usize {
208 var dst_left = dst;208 var dst_left = dst;
209209
210 while (dst_left.len > 0) {210 while (dst_left.len > 0) {
...@@ -216,7 +216,7 @@ pub fn LinearFifo(...@@ -216,7 +216,7 @@ pub fn LinearFifo(
216 dst_left = dst_left[n..];216 dst_left = dst_left[n..];
217 }217 }
218218
219 return dst[0 .. dst.len - dst_left.len];219 return dst.len - dst_left.len;
220 }220 }
221221
222 /// Returns number of bytes available in fifo222 /// Returns number of bytes available in fifo
...@@ -384,7 +384,7 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -384,7 +384,7 @@ test "LinearFifo(u8, .Dynamic)" {
384 {384 {
385 try fifo.unget("prependedstring");385 try fifo.unget("prependedstring");
386 var result: [30]u8 = undefined;386 var result: [30]u8 = undefined;
387 testing.expectEqualSlices(u8, "prependedstringabcdefghij", fifo.read(&result));387 testing.expectEqualSlices(u8, "prependedstringabcdefghij", result[0..fifo.read(&result)]);
388 }388 }
389389
390 fifo.shrink(0);390 fifo.shrink(0);
...@@ -392,7 +392,7 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -392,7 +392,7 @@ test "LinearFifo(u8, .Dynamic)" {
392 {392 {
393 try fifo.print("{}, {}!", "Hello", "World");393 try fifo.print("{}, {}!", "Hello", "World");
394 var result: [30]u8 = undefined;394 var result: [30]u8 = undefined;
395 testing.expectEqualSlices(u8, "Hello, World!", fifo.read(&result));395 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
396 testing.expectEqual(@as(usize, 0), fifo.readableLength());396 testing.expectEqual(@as(usize, 0), fifo.readableLength());
397 }397 }
398}398}