about summary refs log tree commit diff
diff options
context:
space:
mode:
authorXuanwo <github@xuanwo.io>2021-12-29 14:02:20 +0800
committerXuanwo <github@xuanwo.io>2021-12-29 14:02:20 +0800
commitb07ae1c4d5232abcb89151eb64d81631d11a5d14 (patch)
tree99f64c4926e2be3cc98f27208abbba9425ee4d95
parent9166428be18f5348b2c6cb5301986d29e5a0af9c (diff)
downloadrust-b07ae1c4d5232abcb89151eb64d81631d11a5d14.tar.gz
rust-b07ae1c4d5232abcb89151eb64d81631d11a5d14.zip
Address comments
Signed-off-by: Xuanwo <github@xuanwo.io>
-rw-r--r--library/std/src/ffi/os_str.rs12
-rw-r--r--library/std/src/sys_common/wtf8.rs8
2 files changed, 10 insertions, 10 deletions
diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs
index 9b853fba41b..b3ad3fe8c2c 100644
--- a/library/std/src/ffi/os_str.rs
+++ b/library/std/src/ffi/os_str.rs
@@ -266,7 +266,7 @@ impl OsString {
         self.inner.reserve(additional)
     }
 
-    /// Tries to reserve capacity for at least `additional` more elements to be inserted
+    /// Tries to reserve capacity for at least `additional` more length units
     /// in the given `OsString`. The string 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
@@ -288,7 +288,7 @@ impl OsString {
     ///     let mut s = OsString::new();
     ///
     ///     // Pre-reserve the memory, exiting if we can't
-    ///     s.try_reserve(data.len())?;
+    ///     s.try_reserve(OsString::from(data).len())?;
     ///
     ///     // Now we know this can't OOM in the middle of our complex work
     ///     s.push(data);
@@ -329,12 +329,12 @@ impl OsString {
     }
 
     /// Tries to reserve the minimum capacity for exactly `additional`
-    /// elements to be inserted in the given `OsString`. After calling
+    /// 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(())`.
     /// Does nothing if the capacity is already sufficient.
     ///
-    /// Note that the allocator may give the collection more space than it
+    /// Note that the allocator may give the `OsString` more space than it
     /// requests. Therefore, capacity can not be relied upon to be precisely
     /// minimal. Prefer [`try_reserve`] if future insertions are expected.
     ///
@@ -353,10 +353,10 @@ impl OsString {
     /// use std::collections::TryReserveError;
     ///
     /// fn find_max_slow(data: &str) -> Result<OsString, TryReserveError> {
-    ///     let mut s = OsString::from(data);
+    ///     let mut s = OsString::new();
     ///
     ///     // Pre-reserve the memory, exiting if we can't
-    ///     s.try_reserve_exact(data.len())?;
+    ///     s.try_reserve_exact(OsString::from(data).len())?;
     ///
     ///     // Now we know this can't OOM in the middle of our complex work
     ///     s.push(data);
diff --git a/library/std/src/sys_common/wtf8.rs b/library/std/src/sys_common/wtf8.rs
index 3f3f4abd214..7a6e6246357 100644
--- a/library/std/src/sys_common/wtf8.rs
+++ b/library/std/src/sys_common/wtf8.rs
@@ -232,8 +232,8 @@ impl Wtf8Buf {
         self.bytes.reserve(additional)
     }
 
-    /// Tries to reserve capacity for at least `additional` more elements to be inserted
-    /// in the given `Wtf8Buf`. The collection may reserve more space to avoid
+    /// Tries to reserve capacity for at least `additional` more length units
+    /// in the given `Wtf8Buf`. The `Wtf8Buf` 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.
@@ -253,12 +253,12 @@ impl Wtf8Buf {
     }
 
     /// Tries to reserve the minimum capacity for exactly `additional`
-    /// elements to be inserted in the given `Wtf8Buf`. After calling
+    /// length units in the given `Wtf8Buf`. 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
+    /// Note that the allocator may give the `Wtf8Buf` more space than it
     /// requests. Therefore, capacity can not be relied upon to be precisely
     /// minimal. Prefer [`try_reserve`] if future insertions are expected.
     ///