Skip to content

Commit 38c8836

Browse files
committed
docs: Changed docs for size_of to describe size as a stride offset
Current description of `std::mem::size_of` is ambiguous, and the `std::intrinsics::size_of` description incorrectly defines size as the number of bytes necessary to exactly overwrite a value, not including the padding between elements necessary in a vector or structure.
1 parent 855fb61 commit 38c8836

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/libcore/intrinsics.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,8 @@ extern "rust-intrinsic" {
192192

193193
/// The size of a type in bytes.
194194
///
195-
/// This is the exact number of bytes in memory taken up by a
196-
/// value of the given type. In other words, a memset of this size
197-
/// would *exactly* overwrite a value. When laid out in vectors
198-
/// and structures there may be additional padding between
199-
/// elements.
195+
/// More specifically, this is the offset in bytes between successive
196+
/// items of the same type, including alignment padding.
200197
pub fn size_of<T>() -> usize;
201198

202199
/// Moves a value to an uninitialized memory location.

src/libcore/mem.rs

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ pub fn forget<T>(t: T) {
117117

118118
/// Returns the size of a type in bytes.
119119
///
120+
/// More specifically, this is the offset in bytes between successive
121+
/// items of the same type, including alignment padding.
122+
///
120123
/// # Examples
121124
///
122125
/// ```

0 commit comments

Comments
 (0)