about summary refs log tree commit diff
diff options
context:
space:
mode:
authorXuanwo <github@xuanwo.io>2022-01-03 17:35:38 +0800
committerXuanwo <github@xuanwo.io>2022-01-03 17:35:38 +0800
commitedae82e5e4b29718ee060b86cffa0d702cabc713 (patch)
tree519d12429016ee0b9a0cdc01ce7d32e034a1aca2
parentb5da80871d5e22401e03ce5ed73200ece8bdc7a6 (diff)
downloadrust-edae82e5e4b29718ee060b86cffa0d702cabc713.tar.gz
rust-edae82e5e4b29718ee060b86cffa0d702cabc713.zip
std: Implement try_reserve and try_reserve_exact on PathBuf
Signed-off-by: Xuanwo <github@xuanwo.io>
-rw-r--r--library/std/src/path.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs
index 7d401cff591..9104ad46fb4 100644
--- a/library/std/src/path.rs
+++ b/library/std/src/path.rs
@@ -72,6 +72,7 @@ mod tests;
 
 use crate::borrow::{Borrow, Cow};
 use crate::cmp;
+use crate::collections::TryReserveError;
 use crate::error::Error;
 use crate::fmt;
 use crate::fs;
@@ -1512,6 +1513,15 @@ impl PathBuf {
         self.inner.reserve(additional)
     }
 
+    /// Invokes [`try_reserve`] on the underlying instance of [`OsString`].
+    ///
+    /// [`try_reserve`]: OsString::try_reserve
+    #[unstable(feature = "try_reserve_2", issue = "91789")]
+    #[inline]
+    pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
+        self.inner.try_reserve(additional)
+    }
+
     /// Invokes [`reserve_exact`] on the underlying instance of [`OsString`].
     ///
     /// [`reserve_exact`]: OsString::reserve_exact
@@ -1521,6 +1531,15 @@ impl PathBuf {
         self.inner.reserve_exact(additional)
     }
 
+    /// Invokes [`try_reserve_exact`] on the underlying instance of [`OsString`].
+    ///
+    /// [`try_reserve_exact`]: OsString::try_reserve_exact
+    #[unstable(feature = "try_reserve_2", issue = "91789")]
+    #[inline]
+    pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
+        self.inner.try_reserve_exact(additional)
+    }
+
     /// Invokes [`shrink_to_fit`] on the underlying instance of [`OsString`].
     ///
     /// [`shrink_to_fit`]: OsString::shrink_to_fit