1
Fork 0

Update the comment some more following CR feedback

This commit is contained in:
Scott McMurray 2018-12-11 22:17:35 -08:00
parent 5c11392b14
commit ac642aba07

View file

@ -748,10 +748,10 @@ impl<T> Vec<T> {
self self
} }
/// Forces the length of a vector to a particular value. /// Forces the length of the vector to `new_len`.
/// ///
/// This is a low-level operation that maintains none of the normal /// This is a low-level operation that maintains none of the normal
/// invariants of the type. Normally changing the length of a `Vec` /// invariants of the type. Normally changing the length of a vector
/// is done using one of the safe operations instead, such as /// is done using one of the safe operations instead, such as
/// [`truncate`], [`resize`], [`extend`], or [`clear`]. /// [`truncate`], [`resize`], [`extend`], or [`clear`].
/// ///
@ -762,14 +762,15 @@ impl<T> Vec<T> {
/// ///
/// # Safety /// # Safety
/// ///
/// - `new_len` must be less than or equal to `capacity()`. /// - `new_len` must be less than or equal to [`capacity()`].
/// - All elements between past the previous end up to the `new_len` /// - The elements at `old_len..new_len` must be initialized.
/// must be initialized. ///
/// [`capacity()`]: #method.capacity
/// ///
/// # Examples /// # Examples
/// ///
/// This method can be useful for situations in which the `Vec` is /// This method can be useful for situations in which the vector
/// serving as a buffer for other code, particularly over FFI: /// is serving as a buffer for other code, particularly over FFI:
/// ///
/// ```no_run /// ```no_run
/// # #![allow(dead_code)] /// # #![allow(dead_code)]
@ -786,7 +787,7 @@ impl<T> Vec<T> {
/// # } /// # }
/// # impl StreamWrapper { /// # impl StreamWrapper {
/// pub fn get_dictionary(&self) -> Option<Vec<u8>> { /// pub fn get_dictionary(&self) -> Option<Vec<u8>> {
/// // Per the docs, "32768 bytes is always enough". /// // Per the FFI method's docs, "32768 bytes is always enough".
/// let mut dict = Vec::with_capacity(32_768); /// let mut dict = Vec::with_capacity(32_768);
/// let mut dict_length = 0; /// let mut dict_length = 0;
/// unsafe { /// unsafe {
@ -816,7 +817,8 @@ impl<T> Vec<T> {
/// } /// }
/// ``` /// ```
/// ///
/// (Instead, one would normally use [`clear`] in this situation.) /// Normally, here, one would use [`clear`] instead to correctly drop
/// the contents and thus not leak memory.
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn set_len(&mut self, new_len: usize) { pub unsafe fn set_len(&mut self, new_len: usize) {