Skip to content

Commit

Permalink
allow BufReader::peek to be called on unsized types
Browse files Browse the repository at this point in the history
  • Loading branch information
lolbinarycat committed Aug 28, 2024
1 parent 600edc9 commit 6280499
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion library/std/src/io/buffered/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ impl<R: Read> BufReader<R> {
pub fn with_capacity(capacity: usize, inner: R) -> BufReader<R> {
BufReader { inner, buf: Buffer::with_capacity(capacity) }
}
}

impl<R: Read + ?Sized> BufReader<R> {
/// Attempt to look ahead `n` bytes.
///
/// `n` must be less than `capacity`.
Expand All @@ -117,7 +119,10 @@ impl<R: Read> BufReader<R> {
/// assert_eq!(&s, "hello");
/// ```
#[unstable(feature = "bufreader_peek", issue = "128405")]
pub fn peek(&mut self, n: usize) -> io::Result<&[u8]> {
pub fn peek(&mut self, n: usize) -> io::Result<&[u8]>
where
R: ?Sized,
{
assert!(n <= self.capacity());
while n > self.buf.buffer().len() {
if self.buf.pos() > 0 {
Expand Down

0 comments on commit 6280499

Please sign in to comment.