Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify how BytesMut::zeroed works and advantages to manual impl #714

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,14 @@ impl BytesMut {
}
}

/// Creates a new `BytesMut`, which is initialized with zero.
/// 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
/// with zeros.
///
/// On some platforms or allocators this function may be faster than
/// a manual implementation.
///
/// # Examples
///
Expand All @@ -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));
/// ```
Expand Down