From 3443ca5a0be21cdb2424bd20d49746bd622ed195 Mon Sep 17 00:00:00 2001 From: vvvviiv Date: Tue, 9 Jul 2024 20:13:09 +0800 Subject: [PATCH] docs: clarify the behavior of `Buf::chunk` (#717) --- src/buf/buf_impl.rs | 8 +++++--- src/buf/buf_mut.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/buf/buf_impl.rs b/src/buf/buf_impl.rs index 38ecf4bd9..c44d4fb38 100644 --- a/src/buf/buf_impl.rs +++ b/src/buf/buf_impl.rs @@ -141,9 +141,11 @@ 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. + /// This function should never panic. `chunk()` should return an empty + /// slice **if and only if** `remaining()` returns 0. In other words, + /// `chunk()` returning an empty slice implies that `remaining()` will + /// return 0 and `remaining()` returning 0 implies that `chunk()` will + /// return an empty slice. // The `chunk` method was previously called `bytes`. This alias makes the rename // more easily discoverable. #[cfg_attr(docsrs, doc(alias = "bytes"))] diff --git a/src/buf/buf_mut.rs b/src/buf/buf_mut.rs index 304e11b13..e13278d2c 100644 --- a/src/buf/buf_mut.rs +++ b/src/buf/buf_mut.rs @@ -165,7 +165,7 @@ pub unsafe trait BufMut { /// /// # Implementer notes /// - /// This function should never panic. `chunk_mut` should return an empty + /// This function should never panic. `chunk_mut()` should return an empty /// slice **if and only if** `remaining_mut()` returns 0. In other words, /// `chunk_mut()` returning an empty slice implies that `remaining_mut()` will /// return 0 and `remaining_mut()` returning 0 implies that `chunk_mut()` will