From e983e1b83d49c2f3018decb1690f83e7a47d953f Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Wed, 19 Jun 2024 04:39:36 +0200 Subject: [PATCH 1/2] Clarify how `BytesMut::zeroed` works and advantages to manual impl --- src/bytes_mut.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs index 537f01ad3..9265ce001 100644 --- a/src/bytes_mut.rs +++ b/src/bytes_mut.rs @@ -264,7 +264,14 @@ impl BytesMut { } } - /// Creates a new `BytesMut`, which is initialized with zero. + /// Creates a new `BytesMut`, with the length initialized with zeros. + /// + /// The resulting object has a length of `len` and a capacity greater + /// than or equal to `len`. The entire length of the object will be filled + /// with zeros. + /// + /// On some platforms or allocators this function may be faster than + /// a manual implementation. /// /// # Examples /// @@ -273,6 +280,7 @@ impl BytesMut { /// /// let zeros = BytesMut::zeroed(42); /// + /// assert!(zeros.capacity() >= 42); /// assert_eq!(zeros.len(), 42); /// zeros.into_iter().for_each(|x| assert_eq!(x, 0)); /// ``` From 8c21a958e0cf78a76588a42a4c8ab580065e2681 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Fri, 21 Jun 2024 13:59:35 +0200 Subject: [PATCH 2/2] Update src/bytes_mut.rs Co-authored-by: Alice Ryhl --- src/bytes_mut.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs index 9265ce001..a01b29634 100644 --- a/src/bytes_mut.rs +++ b/src/bytes_mut.rs @@ -264,7 +264,7 @@ impl BytesMut { } } - /// Creates a new `BytesMut`, with the length initialized with zeros. + /// Creates a new `BytesMut` containing `len` zeros. /// /// The resulting object has a length of `len` and a capacity greater /// than or equal to `len`. The entire length of the object will be filled