diff --git a/src/buf/buf_impl.rs b/src/buf/buf_impl.rs index a33c8a42d..a87bf3304 100644 --- a/src/buf/buf_impl.rs +++ b/src/buf/buf_impl.rs @@ -125,8 +125,9 @@ pub trait Buf { /// # Implementer notes /// /// This function should never panic. Once the end of the buffer is reached, - /// i.e., `Buf::remaining` returns 0, calls to `chunk()` should return an - /// empty slice. + /// i.e., `Buf::remaining` returns 0, calls to `chunk()` must return an + /// empty slice. If there is remaining data, calls must return a slice with at + /// least 1 byte. // The `chunk` method was previously called `bytes`. This alias makes the rename // more easily discoverable. #[cfg_attr(docsrs, doc(alias = "bytes"))] @@ -285,7 +286,7 @@ pub trait Buf { /// /// This function panics if there is no more remaining data in `self`. fn get_u8(&mut self) -> u8 { - assert!(self.remaining() >= 1); + assert!(self.chunk().len() >= 1); let ret = self.chunk()[0]; self.advance(1); ret @@ -308,7 +309,7 @@ pub trait Buf { /// /// This function panics if there is no more remaining data in `self`. fn get_i8(&mut self) -> i8 { - assert!(self.remaining() >= 1); + assert!(self.chunk().len() >= 1); let ret = self.chunk()[0] as i8; self.advance(1); ret