| ... | ... | @@ -203,8 +203,8 @@ pub fn LinearFifo( |
| 203 | 203 | return c; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | | /// Read data from the fifo into `dst`, returns slice of bytes copied (subslice of `dst`) |
| 207 | | pub fn read(self: *Self, dst: []T) []T { |
| 206 | /// Read data from the fifo into `dst`, returns number of bytes copied. |
| 207 | pub fn read(self: *Self, dst: []T) usize { |
| 208 | 208 | var dst_left = dst; |
| 209 | 209 | |
| 210 | 210 | while (dst_left.len > 0) { |
| ... | ... | @@ -216,7 +216,7 @@ pub fn LinearFifo( |
| 216 | 216 | dst_left = dst_left[n..]; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | | return dst[0 .. dst.len - dst_left.len]; |
| 219 | return dst.len - dst_left.len; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /// Returns number of bytes available in fifo |
| ... | ... | @@ -384,7 +384,7 @@ test "LinearFifo(u8, .Dynamic)" { |
| 384 | 384 | { |
| 385 | 385 | try fifo.unget("prependedstring"); |
| 386 | 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 | } |
| 389 | 389 | |
| 390 | 390 | fifo.shrink(0); |
| ... | ... | @@ -392,7 +392,7 @@ test "LinearFifo(u8, .Dynamic)" { |
| 392 | 392 | { |
| 393 | 393 | try fifo.print("{}, {}!", "Hello", "World"); |
| 394 | 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 | 396 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); |
| 397 | 397 | } |
| 398 | 398 | } |