@@ -1137,14 +1137,40 @@ impl PathBuf {
1137
1137
///
1138
1138
/// ```
1139
1139
/// use std::path::PathBuf;
1140
- ///
1140
+ ///
1141
1141
/// let path = PathBuf::new();
1142
1142
/// ```
1143
1143
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1144
1144
pub fn new ( ) -> PathBuf {
1145
1145
PathBuf { inner : OsString :: new ( ) }
1146
1146
}
1147
1147
1148
+ /// Creates a new `PathBuf` with a given capacity used to create the
1149
+ /// internal [`OsString`]. See [`with_capacity`] defined on [`OsString`].
1150
+ ///
1151
+ /// # Examples
1152
+ ///
1153
+ /// ```
1154
+ /// use std::path::PathBuf;
1155
+ ///
1156
+ /// let path = PathBuf::with_capacity(10);
1157
+ /// let capacity = path.capacity();
1158
+ ///
1159
+ /// // This push is done without reallocating
1160
+ /// path.push(r"C:\");
1161
+ ///
1162
+ /// assert_eq!(capacity, path.capacity());
1163
+ /// ```
1164
+ ///
1165
+ /// [`with_capacity`]: ../ffi/struct.OsString.html#method.with_capacity
1166
+ /// [`OsString`]: ../ffi/struct.OsString.html
1167
+ #[ stable( feature = "path_buf_os_string_methods" , since = "1.33.0" ) ]
1168
+ pub fn with_capacity ( capacity : usize ) -> PathBuf {
1169
+ PathBuf {
1170
+ inner : OsString :: with_capacity ( capacity)
1171
+ }
1172
+ }
1173
+
1148
1174
/// Coerces to a [`Path`] slice.
1149
1175
///
1150
1176
/// [`Path`]: struct.Path.html
@@ -1373,6 +1399,60 @@ impl PathBuf {
1373
1399
let rw = Box :: into_raw ( self . inner . into_boxed_os_str ( ) ) as * mut Path ;
1374
1400
unsafe { Box :: from_raw ( rw) }
1375
1401
}
1402
+
1403
+ /// Invokes [`capacity`] on the underlying instance of [`OsString`].
1404
+ ///
1405
+ /// [`capacity`]: ../ffi/struct.OsString.html#method.capacity
1406
+ /// [`OsString`]: ../ffi/struct.OsString.html
1407
+ #[ stable( feature = "path_buf_os_string_methods" , since = "1.33.0" ) ]
1408
+ pub fn capacity ( self ) -> usize {
1409
+ self . inner . capacity ( )
1410
+ }
1411
+
1412
+ /// Invokes [`clear`] on the underlying instance of [`OsString`].
1413
+ ///
1414
+ /// [`clear`]: ../ffi/struct.OsString.html#method.clear
1415
+ /// [`OsString`]: ../ffi/struct.OsString.html
1416
+ #[ stable( feature = "path_buf_os_string_methods" , since = "1.33.0" ) ]
1417
+ pub fn clear ( mut self ) {
1418
+ self . inner . clear ( )
1419
+ }
1420
+
1421
+ /// Invokes [`reserve`] on the underlying instance of [`OsString`].
1422
+ ///
1423
+ /// [`reserve`]: ../ffi/struct.OsString.html#method.reserve
1424
+ /// [`OsString`]: ../ffi/struct.OsString.html
1425
+ #[ stable( feature = "path_buf_os_string_methods" , since = "1.33.0" ) ]
1426
+ pub fn reserve ( mut self , additional : usize ) {
1427
+ self . inner . reserve ( additional)
1428
+ }
1429
+
1430
+ /// Invokes [`reserve_exact`] on the underlying instance of [`OsString`].
1431
+ ///
1432
+ /// [`reserve_exact`]: ../ffi/struct.OsString.html#method.reserve_exact
1433
+ /// [`OsString`]: ../ffi/struct.OsString.html
1434
+ #[ stable( feature = "path_buf_os_string_methods" , since = "1.33.0" ) ]
1435
+ pub fn reserve_exact ( mut self , additional : usize ) {
1436
+ self . inner . reserve_exact ( additional)
1437
+ }
1438
+
1439
+ /// Invokes [`shrink_to_fit`] on the underlying instance of [`OsString`].
1440
+ ///
1441
+ /// [`shrink_to_fit`]: ../ffi/struct.OsString.html#method.shrink_to_fit
1442
+ /// [`OsString`]: ../ffi/struct.OsString.html
1443
+ #[ stable( feature = "path_buf_os_string_methods" , since = "1.33.0" ) ]
1444
+ pub fn shrink_to_fit ( mut self ) {
1445
+ self . inner . shrink_to_fit ( )
1446
+ }
1447
+
1448
+ /// Invokes [`shrink_to`] on the underlying instance of [`OsString`].
1449
+ ///
1450
+ /// [`shrink_to`]: ../ffi/struct.OsString.html#method.shrink_to
1451
+ /// [`OsString`]: ../ffi/struct.OsString.html
1452
+ #[ stable( feature = "path_buf_os_string_methods" , since = "1.33.0" ) ]
1453
+ pub fn shrink_to ( mut self , min_capacity : usize ) {
1454
+ self . inner . shrink_to ( min_capacity)
1455
+ }
1376
1456
}
1377
1457
1378
1458
#[ stable( feature = "box_from_path" , since = "1.17.0" ) ]
0 commit comments