Function peek [src]
Returns the next len bytes from the stream, filling the buffer as
necessary.
Invalidates previously returned values from peek.
Asserts that the Reader was initialized with a buffer capacity at
least as big as len.
If there are fewer than len bytes left in the stream, error.EndOfStream
is returned instead.
See also:
peek
toss
Prototype
pub fn peek(r: *Reader, n: usize) Error![]u8
Parameters
r: *Reader
n: usize
Possible Errors
See the Reader
implementation for detailed diagnostics.
Example
test peek {
var r: Reader = .fixed("abc");
try testing.expectEqualStrings("ab", try r.peek(2));
try testing.expectEqualStrings("a", try r.peek(1));
}
Source
pub fn peek(r: *Reader, n: usize) Error![]u8 {
try r.fill(n);
return r.buffer[r.seek..][0..n];
}