BinaryHeap { data: vec![] }
}
- /// Creates an empty `BinaryHeap` with a specific capacity.
- /// This preallocates enough memory for `capacity` elements,
- /// so that the `BinaryHeap` does not have to be reallocated
- /// until it contains at least that many values.
+ /// Creates an empty `BinaryHeap` with at least the specified capacity.
+ ///
+ /// The binary heap will be able to hold at least `capacity` elements without
+ /// reallocating. This method is allowed to allocate for more elements than
+ /// `capacity`. If `capacity` is 0, the binary heap will not allocate.
///
/// # Examples
///
self.data.capacity()
}
- /// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
- /// given `BinaryHeap`. Does nothing if the capacity is already sufficient.
+ /// Reserves the minimum capacity for at least `additional` elements more than
+ /// the current length. Unlike [`reserve`], this will not
+ /// deliberately over-allocate to speculatively avoid frequent allocations.
+ /// After calling `reserve_exact`, capacity will be greater than or equal to
+ /// `self.len() + additional`. Does nothing if the capacity is already
+ /// sufficient.
///
- /// Note that the allocator may give the collection more space than it requests. Therefore
- /// capacity can not be relied upon to be precisely minimal. Prefer [`reserve`] if future
- /// insertions are expected.
+ /// [`reserve`]: BinaryHeap::reserve
///
/// # Panics
///
- /// Panics if the new capacity overflows `usize`.
+ /// Panics if the new capacity overflows [`usize`].
///
/// # Examples
///
self.data.reserve_exact(additional);
}
- /// Reserves capacity for at least `additional` more elements to be inserted in the
- /// `BinaryHeap`. The collection may reserve more space to avoid frequent reallocations.
+ /// Reserves capacity for at least `additional` elements more than the
+ /// current length. The allocator may reserve more space to speculatively
+ /// avoid frequent allocations. After calling `reserve`,
+ /// capacity will be greater than or equal to `self.len() + additional`.
+ /// Does nothing if capacity is already sufficient.
///
/// # Panics
///
- /// Panics if the new capacity overflows `usize`.
+ /// Panics if the new capacity overflows [`usize`].
///
/// # Examples
///
self.data.reserve(additional);
}
- /// Tries to reserve the minimum capacity for exactly `additional`
- /// elements to be inserted in the given `BinaryHeap<T>`. After calling
- /// `try_reserve_exact`, capacity will be greater than or equal to
- /// `self.len() + additional` if it returns `Ok(())`.
+ /// Tries to reserve the minimum capacity for at least `additional` elements
+ /// more than the current length. Unlike [`try_reserve`], this will not
+ /// deliberately over-allocate to speculatively avoid frequent allocations.
+ /// After calling `try_reserve_exact`, capacity will be greater than or
+ /// equal to `self.len() + additional` if it returns `Ok(())`.
/// Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
self.data.try_reserve_exact(additional)
}
- /// Tries to reserve capacity for at least `additional` more elements to be inserted
- /// in the given `BinaryHeap<T>`. The collection may reserve more space to avoid
- /// frequent reallocations. After calling `try_reserve`, capacity will be
- /// greater than or equal to `self.len() + additional`. Does nothing if
- /// capacity is already sufficient.
+ /// Tries to reserve capacity for at least `additional` elements more than the
+ /// current length. The allocator may reserve more space to speculatively
+ /// avoid frequent allocations. After calling `try_reserve`, capacity will be
+ /// greater than or equal to `self.len() + additional` if it returns
+ /// `Ok(())`. Does nothing if capacity is already sufficient.
///
/// # Errors
///
self.cap() - 1
}
- /// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
+ /// Reserves the minimum capacity for at least `additional` more elements to be inserted in the
/// given deque. Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it requests. Therefore
}
/// Reserves capacity for at least `additional` more elements to be inserted in the given
- /// deque. The collection may reserve more space to avoid frequent reallocations.
+ /// deque. The collection may reserve more space to speculatively avoid frequent reallocations.
///
/// # Panics
///
}
}
- /// Tries to reserve the minimum capacity for exactly `additional` more elements to
+ /// Tries to reserve the minimum capacity for at least `additional` more elements to
/// be inserted in the given deque. After calling `try_reserve_exact`,
- /// capacity will be greater than or equal to `self.len() + additional`.
- /// Does nothing if the capacity is already sufficient.
+ /// capacity will be greater than or equal to `self.len() + additional` if
+ /// it returns `Ok(())`. Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
/// requests. Therefore, capacity can not be relied upon to be precisely
}
/// Tries to reserve capacity for at least `additional` more elements to be inserted
- /// in the given deque. The collection may reserve more space to avoid
+ /// in the given deque. The collection may reserve more space to speculatively avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
- /// greater than or equal to `self.len() + additional`. Does nothing if
- /// capacity is already sufficient.
+ /// greater than or equal to `self.len() + additional` if it returns
+ /// `Ok(())`. Does nothing if capacity is already sufficient.
///
/// # Errors
///
String { vec: Vec::new() }
}
- /// Creates a new empty `String` with a particular capacity.
+ /// Creates a new empty `String` with at least the specified capacity.
///
/// `String`s have an internal buffer to hold their data. The capacity is
/// the length of that buffer, and can be queried with the [`capacity`]
/// method. This method creates an empty `String`, but one with an initial
- /// buffer that can hold `capacity` bytes. This is useful when you may be
- /// appending a bunch of data to the `String`, reducing the number of
+ /// buffer that can hold at least `capacity` bytes. This is useful when you
+ /// may be appending a bunch of data to the `String`, reducing the number of
/// reallocations it needs to do.
///
/// [`capacity`]: String::capacity
self.vec.capacity()
}
- /// Ensures that this `String`'s capacity is at least `additional` bytes
- /// larger than its length.
- ///
- /// The capacity may be increased by more than `additional` bytes if it
- /// chooses, to prevent frequent reallocations.
- ///
- /// If you do not want this "at least" behavior, see the [`reserve_exact`]
- /// method.
+ /// Reserves capacity for at least `additional` bytes more than the
+ /// current length. The allocator may reserve more space to speculatively
+ /// avoid frequent allocations. After calling `reserve`,
+ /// capacity will be greater than or equal to `self.len() + additional`.
+ /// Does nothing if capacity is already sufficient.
///
/// # Panics
///
/// Panics if the new capacity overflows [`usize`].
///
- /// [`reserve_exact`]: String::reserve_exact
- ///
/// # Examples
///
/// Basic usage:
/// s.push('a');
/// s.push('b');
///
- /// // s now has a length of 2 and a capacity of 10
+ /// // s now has a length of 2 and a capacity of at least 10
+ /// let capacity = s.capacity();
/// assert_eq!(2, s.len());
- /// assert_eq!(10, s.capacity());
+ /// assert!(capacity >= 10);
///
- /// // Since we already have an extra 8 capacity, calling this...
+ /// // Since we already have at least an extra 8 capacity, calling this...
/// s.reserve(8);
///
/// // ... doesn't actually increase.
- /// assert_eq!(10, s.capacity());
+ /// assert_eq!(capacity, s.capacity());
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
self.vec.reserve(additional)
}
- /// Ensures that this `String`'s capacity is `additional` bytes
- /// larger than its length.
- ///
- /// Consider using the [`reserve`] method unless you absolutely know
- /// better than the allocator.
+ /// Reserves the minimum capacity for at least `additional` bytes more than
+ /// the current length. Unlike [`reserve`], this will not
+ /// deliberately over-allocate to speculatively avoid frequent allocations.
+ /// After calling `reserve_exact`, capacity will be greater than or equal to
+ /// `self.len() + additional`. Does nothing if the capacity is already
+ /// sufficient.
///
/// [`reserve`]: String::reserve
///
/// # Panics
///
- /// Panics if the new capacity overflows `usize`.
+ /// Panics if the new capacity overflows [`usize`].
///
/// # Examples
///
/// s.push('a');
/// s.push('b');
///
- /// // s now has a length of 2 and a capacity of 10
+ /// // s now has a length of 2 and a capacity of at least 10
+ /// let capacity = s.capacity();
/// assert_eq!(2, s.len());
- /// assert_eq!(10, s.capacity());
+ /// assert!(capacity >= 10);
///
- /// // Since we already have an extra 8 capacity, calling this...
+ /// // Since we already have at least an extra 8 capacity, calling this...
/// s.reserve_exact(8);
///
/// // ... doesn't actually increase.
- /// assert_eq!(10, s.capacity());
+ /// assert_eq!(capacity, s.capacity());
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
self.vec.reserve_exact(additional)
}
- /// Tries to reserve capacity for at least `additional` more elements to be inserted
- /// in the given `String`. The collection may reserve more space to avoid
- /// frequent reallocations. After calling `reserve`, capacity will be
- /// greater than or equal to `self.len() + additional`. Does nothing if
- /// capacity is already sufficient.
+ /// Tries to reserve capacity for at least `additional` bytes more than the
+ /// current length. The allocator may reserve more space to speculatively
+ /// avoid frequent allocations. After calling `try_reserve`, capacity will be
+ /// greater than or equal to `self.len() + additional` if it returns
+ /// `Ok(())`. Does nothing if capacity is already sufficient.
///
/// # Errors
///
self.vec.try_reserve(additional)
}
- /// Tries to reserve the minimum capacity for exactly `additional` more elements to
- /// be inserted in the given `String`. After calling `try_reserve_exact`,
- /// capacity will be greater than or equal to `self.len() + additional`.
+ /// Tries to reserve the minimum capacity for at least `additional` bytes
+ /// more than the current length. Unlike [`try_reserve`], this will not
+ /// deliberately over-allocate to speculatively avoid frequent allocations.
+ /// After calling `try_reserve_exact`, capacity will be greater than or
+ /// equal to `self.len() + additional` if it returns `Ok(())`.
/// Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
Vec { buf: RawVec::NEW, len: 0 }
}
- /// Constructs a new, empty `Vec<T>` with the specified capacity.
+ /// Constructs a new, empty `Vec<T>` with at least the specified capacity.
///
- /// The vector will be able to hold exactly `capacity` elements without
- /// reallocating. If `capacity` is 0, the vector will not allocate.
+ /// The vector will be able to hold at least `capacity` elements without
+ /// reallocating. This method is allowed to allocate for more elements than
+ /// `capacity`. If `capacity` is 0, the vector will not allocate.
///
/// It is important to note that although the returned vector has the
- /// *capacity* specified, the vector will have a zero *length*. For an
- /// explanation of the difference between length and capacity, see
+ /// minimum *capacity* specified, the vector will have a zero *length*. For
+ /// an explanation of the difference between length and capacity, see
/// *[Capacity and reallocation]*.
///
+ /// If it is imporant to know the exact allocated capacity of a `Vec`,
+ /// always use the [`capacity`] method after construction.
+ ///
+ /// For `Vec<T>` where `T` is a zero-sized type, there will be no allocation
+ /// and the capacity will always be `usize::MAX`.
+ ///
/// [Capacity and reallocation]: #capacity-and-reallocation
+ /// [`capacity`]: Vec::capacity
///
/// # Panics
///
///
/// // The vector contains no items, even though it has capacity for more
/// assert_eq!(vec.len(), 0);
- /// assert_eq!(vec.capacity(), 10);
+ /// assert!(vec.capacity() >= 10);
///
/// // These are all done without reallocating...
/// for i in 0..10 {
/// vec.push(i);
/// }
/// assert_eq!(vec.len(), 10);
- /// assert_eq!(vec.capacity(), 10);
+ /// assert!(vec.capacity() >= 10);
///
/// // ...but this may make the vector reallocate
/// vec.push(11);
/// assert_eq!(vec.len(), 11);
/// assert!(vec.capacity() >= 11);
+ ///
+ /// // A vector of a zero-sized type will always over-allocate, since no
+ /// // allocation is necessary
+ /// let vec_units = Vec::<()>::with_capacity(10);
+ /// assert_eq!(vec_units.capacity(), usize::MAX);
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
Vec { buf: RawVec::new_in(alloc), len: 0 }
}
- /// Constructs a new, empty `Vec<T, A>` with the specified capacity with the provided
- /// allocator.
+ /// Constructs a new, empty `Vec<T, A>` with at least the specified capacity
+ /// with the provided allocator.
///
- /// The vector will be able to hold exactly `capacity` elements without
- /// reallocating. If `capacity` is 0, the vector will not allocate.
+ /// The vector will be able to hold at least `capacity` elements without
+ /// reallocating. This method is allowed to allocate for more elements than
+ /// `capacity`. If `capacity` is 0, the vector will not allocate.
///
/// It is important to note that although the returned vector has the
- /// *capacity* specified, the vector will have a zero *length*. For an
- /// explanation of the difference between length and capacity, see
+ /// minimum *capacity* specified, the vector will have a zero *length*. For
+ /// an explanation of the difference between length and capacity, see
/// *[Capacity and reallocation]*.
///
+ /// If it is imporant to know the exact allocated capacity of a `Vec`,
+ /// always use the [`capacity`] method after construction.
+ ///
+ /// For `Vec<T, A>` where `T` is a zero-sized type, there will be no allocation
+ /// and the capacity will always be `usize::MAX`.
+ ///
/// [Capacity and reallocation]: #capacity-and-reallocation
+ /// [`capacity`]: Vec::capacity
///
/// # Panics
///
/// vec.push(11);
/// assert_eq!(vec.len(), 11);
/// assert!(vec.capacity() >= 11);
+ ///
+ /// // A vector of a zero-sized type will always over-allocate, since no
+ /// // allocation is necessary
+ /// let vec_units = Vec::<(), System>::with_capacity_in(10, System);
+ /// assert_eq!(vec_units.capacity(), usize::MAX);
/// ```
#[cfg(not(no_global_oom_handling))]
#[inline]
}
/// Reserves capacity for at least `additional` more elements to be inserted
- /// in the given `Vec<T>`. The collection may reserve more space to avoid
- /// frequent reallocations. After calling `reserve`, capacity will be
- /// greater than or equal to `self.len() + additional`. Does nothing if
- /// capacity is already sufficient.
+ /// in the given `Vec<T>`. The collection may reserve more space to
+ /// speculatively avoid frequent reallocations. After calling `reserve`,
+ /// capacity will be greater than or equal to `self.len() + additional`.
+ /// Does nothing if capacity is already sufficient.
///
/// # Panics
///
self.buf.reserve(self.len, additional);
}
- /// Reserves the minimum capacity for exactly `additional` more elements to
- /// be inserted in the given `Vec<T>`. After calling `reserve_exact`,
- /// capacity will be greater than or equal to `self.len() + additional`.
- /// Does nothing if the capacity is already sufficient.
+ /// Reserves the minimum capacity for at least `additional` more elements to
+ /// be inserted in the given `Vec<T>`. Unlike [`reserve`], this will not
+ /// deliberately over-allocate to speculatively avoid frequent allocations.
+ /// After calling `reserve_exact`, capacity will be greater than or equal to
+ /// `self.len() + additional`. Does nothing if the capacity is already
+ /// sufficient.
///
/// Note that the allocator may give the collection more space than it
/// requests. Therefore, capacity can not be relied upon to be precisely
}
/// Tries to reserve capacity for at least `additional` more elements to be inserted
- /// in the given `Vec<T>`. The collection may reserve more space to avoid
+ /// in the given `Vec<T>`. The collection may reserve more space to speculatively avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
- /// greater than or equal to `self.len() + additional`. Does nothing if
- /// capacity is already sufficient.
+ /// greater than or equal to `self.len() + additional` if it returns
+ /// `Ok(())`. Does nothing if capacity is already sufficient.
///
/// # Errors
///
self.buf.try_reserve(self.len, additional)
}
- /// Tries to reserve the minimum capacity for exactly `additional`
- /// elements to be inserted in the given `Vec<T>`. After calling
- /// `try_reserve_exact`, capacity will be greater than or equal to
- /// `self.len() + additional` if it returns `Ok(())`.
+ /// Tries to reserve the minimum capacity for at least `additional`
+ /// elements to be inserted in the given `Vec<T>`. Unlike [`try_reserve`],
+ /// this will not deliberately over-allocate to speculatively avoid frequent
+ /// allocations. After calling `try_reserve_exact`, capacity will be greater
+ /// than or equal to `self.len() + additional` if it returns `Ok(())`.
/// Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
c3.refs.v[1].set(Some(&c2));
}
+#[test]
+fn test_zero_sized_capacity() {
+ for len in [0, 1, 2, 4, 8, 16, 32, 64, 128, 256] {
+ let v = Vec::<()>::with_capacity(len);
+ assert_eq!(v.len(), 0);
+ assert_eq!(v.capacity(), usize::MAX);
+ }
+}
+
#[test]
fn test_zero_sized_vec_push() {
const N: usize = 8;
Default::default()
}
- /// Creates an empty `HashMap` with the specified capacity.
+ /// Creates an empty `HashMap` with at least the specified capacity.
///
/// The hash map will be able to hold at least `capacity` elements without
- /// reallocating. If `capacity` is 0, the hash map will not allocate.
+ /// reallocating. This method is allowed to allocate for more elements than
+ /// `capacity`. If `capacity` is 0, the hash set will not allocate.
///
/// # Examples
///
HashMap { base: base::HashMap::with_hasher(hash_builder) }
}
- /// Creates an empty `HashMap` with the specified capacity, using `hash_builder`
- /// to hash the keys.
+ /// Creates an empty `HashMap` with at least the specified capacity, using
+ /// `hasher` to hash the keys.
///
/// The hash map will be able to hold at least `capacity` elements without
- /// reallocating. If `capacity` is 0, the hash map will not allocate.
+ /// reallocating. This method is allowed to allocate for more elements than
+ /// `capacity`. If `capacity` is 0, the hash map will not allocate.
///
- /// Warning: `hash_builder` is normally randomly generated, and
+ /// Warning: `hasher` is normally randomly generated, and
/// is designed to allow HashMaps to be resistant to attacks that
/// cause many collisions and very poor performance. Setting it
/// manually using this function can expose a DoS attack vector.
///
- /// The `hash_builder` passed should implement the [`BuildHasher`] trait for
+ /// The `hasher` passed should implement the [`BuildHasher`] trait for
/// the HashMap to be useful, see its documentation for details.
///
/// # Examples
/// ```
#[inline]
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
- pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> HashMap<K, V, S> {
- HashMap { base: base::HashMap::with_capacity_and_hasher(capacity, hash_builder) }
+ pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S> {
+ HashMap { base: base::HashMap::with_capacity_and_hasher(capacity, hasher) }
}
/// Returns the number of elements the map can hold without reallocating.
S: BuildHasher,
{
/// Reserves capacity for at least `additional` more elements to be inserted
- /// in the `HashMap`. The collection may reserve more space to avoid
- /// frequent reallocations.
+ /// in the `HashMap`. The collection may reserve more space to speculatively
+ /// avoid frequent reallocations. After calling `reserve`,
+ /// capacity will be greater than or equal to `self.len() + additional`.
+ /// Does nothing if capacity is already sufficient.
///
/// # Panics
///
}
/// Tries to reserve capacity for at least `additional` more elements to be inserted
- /// in the given `HashMap<K, V>`. The collection may reserve more space to avoid
- /// frequent reallocations.
+ /// in the `HashMap`. The collection may reserve more space to speculatively
+ /// avoid frequent reallocations. After calling `reserve`,
+ /// capacity will be greater than or equal to `self.len() + additional` if
+ /// it returns `Ok(())`.
+ /// Does nothing if capacity is already sufficient.
///
/// # Errors
///
/// use std::collections::HashMap;
///
/// let mut map: HashMap<&str, isize> = HashMap::new();
- /// map.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?");
+ /// map.try_reserve(10).expect("why is the test harness OOMing on a handful of bytes?");
/// ```
#[inline]
#[stable(feature = "try_reserve", since = "1.57.0")]
Default::default()
}
- /// Creates an empty `HashSet` with the specified capacity.
+ /// Creates an empty `HashSet` with at least the specified capacity.
///
/// The hash set will be able to hold at least `capacity` elements without
- /// reallocating. If `capacity` is 0, the hash set will not allocate.
+ /// reallocating. This method is allowed to allocate for more elements than
+ /// `capacity`. If `capacity` is 0, the hash set will not allocate.
///
/// # Examples
///
HashSet { base: base::HashSet::with_hasher(hasher) }
}
- /// Creates an empty `HashSet` with the specified capacity, using
+ /// Creates an empty `HashSet` with at least the specified capacity, using
/// `hasher` to hash the keys.
///
/// The hash set will be able to hold at least `capacity` elements without
- /// reallocating. If `capacity` is 0, the hash set will not allocate.
+ /// reallocating. This method is allowed to allocate for more elements than
+ /// `capacity`. If `capacity` is 0, the hash set will not allocate.
///
/// Warning: `hasher` is normally randomly generated, and
/// is designed to allow `HashSet`s to be resistant to attacks that
S: BuildHasher,
{
/// Reserves capacity for at least `additional` more elements to be inserted
- /// in the `HashSet`. The collection may reserve more space to avoid
- /// frequent reallocations.
+ /// in the `HashSet`. The collection may reserve more space to speculatively
+ /// avoid frequent reallocations. After calling `reserve`,
+ /// capacity will be greater than or equal to `self.len() + additional`.
+ /// Does nothing if capacity is already sufficient.
///
/// # Panics
///
}
/// Tries to reserve capacity for at least `additional` more elements to be inserted
- /// in the given `HashSet<K, V>`. The collection may reserve more space to avoid
- /// frequent reallocations.
+ /// in the `HashSet`. The collection may reserve more space to speculatively
+ /// avoid frequent reallocations. After calling `reserve`,
+ /// capacity will be greater than or equal to `self.len() + additional` if
+ /// it returns `Ok(())`.
+ /// Does nothing if capacity is already sufficient.
///
/// # Errors
///
/// ```
/// use std::collections::HashSet;
/// let mut set: HashSet<i32> = HashSet::new();
- /// set.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?");
+ /// set.try_reserve(10).expect("why is the test harness OOMing on a handful of bytes?");
/// ```
#[inline]
#[stable(feature = "try_reserve", since = "1.57.0")]
self.inner.push_slice(&s.as_ref().inner)
}
- /// Creates a new `OsString` with the given capacity.
+ /// Creates a new `OsString` with at least the given capacity.
///
- /// The string will be able to hold exactly `capacity` length units of other
- /// OS strings without reallocating. If `capacity` is 0, the string will not
+ /// The string will be able to hold at least `capacity` length units of other
+ /// OS strings without reallocating. This method is allowed to allocate for
+ /// more units than `capacity`. If `capacity` is 0, the string will not
/// allocate.
///
/// See the main `OsString` documentation information about encoding and capacity units.
}
/// Reserves capacity for at least `additional` more capacity to be inserted
- /// in the given `OsString`.
+ /// in the given `OsString`. Does nothing if the capacity is
+ /// already sufficient.
///
- /// The collection may reserve more space to avoid frequent reallocations.
+ /// The collection may reserve more space to speculatively avoid frequent reallocations.
///
/// See the main `OsString` documentation information about encoding and capacity units.
///
}
/// Tries to reserve capacity for at least `additional` more length units
- /// in the given `OsString`. The string may reserve more space to avoid
+ /// in the given `OsString`. The string may reserve more space to speculatively avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
- /// greater than or equal to `self.len() + additional`. Does nothing if
- /// capacity is already sufficient.
+ /// greater than or equal to `self.len() + additional` if it returns `Ok(())`.
+ /// Does nothing if capacity is already sufficient.
///
/// See the main `OsString` documentation information about encoding and capacity units.
///
self.inner.try_reserve(additional)
}
- /// Reserves the minimum capacity for exactly `additional` more capacity to
+ /// Reserves the minimum capacity for at least `additional` more capacity to
/// be inserted in the given `OsString`. Does nothing if the capacity is
/// already sufficient.
///
self.inner.reserve_exact(additional)
}
- /// Tries to reserve the minimum capacity for exactly `additional`
+ /// Tries to reserve the minimum capacity for at least `additional`
/// more length units in the given `OsString`. After calling
/// `try_reserve_exact`, capacity will be greater than or equal to
/// `self.len() + additional` if it returns `Ok(())`.
BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner)
}
- /// Creates a new `BufWriter<W>` with the specified buffer capacity.
+ /// Creates a new `BufWriter<W>` with at least the specified buffer capacity.
///
/// # Examples
///
- /// Creating a buffer with a buffer of a hundred bytes.
+ /// Creating a buffer with a buffer of at least a hundred bytes.
///
/// ```no_run
/// use std::io::BufWriter;
LineWriter::with_capacity(1024, inner)
}
- /// Creates a new `LineWriter` with a specified capacity for the internal
- /// buffer.
+ /// Creates a new `LineWriter` with at least the specified capacity for the
+ /// internal buffer.
///
/// # Examples
///