Expand PathBuf documentation · qinheping/verify-rust-std@22ffa3d (original) (raw)

`@@ -1153,6 +1153,21 @@ impl FusedIterator for Ancestors<'_> {}

`

1153

1153

```` /// ```


`1154`

`1154`

`///

`

`1155`

`1155`

`/// Which method works best depends on what kind of situation you're in.

`

``

`1156`

`+

///

`

``

`1157`

``` +

/// Note that `PathBuf`` does not always sanitize arguments, for example

```

``

`1158`

`` +

/// [`push`] allows paths built from strings which include separators:

``

``

`1159`

`+

///

`

``

`1160`

`+

/// use std::path::PathBuf;

`

``

`1161`

`+

///

`

``

`1162`

`+

/// let mut path = PathBuf::new();

`

``

`1163`

`+

///

`

``

`1164`

`+

/// path.push(r"C:\");

`

``

`1165`

`+

/// path.push("windows");

`

``

`1166`

`+

/// path.push(r"..\otherdir");

`

``

`1167`

`+

/// path.push("system32");

`

``

`1168`

`+

///

`

``

`1169`

`` +

/// The behaviour of `PathBuf` may be changed to a panic on such inputs

``

``

`1170`

`` +

/// in the future. The [`extend`] method should be used to add multi-part paths.

``

`1156`

`1171`

`#[cfg_attr(not(test), rustc_diagnostic_item = "PathBuf")]

`

`1157`

`1172`

`#[stable(feature = "rust1", since = "1.0.0")]

`

`1158`

`1173`

`pub struct PathBuf {

`

`@@ -1391,6 +1406,9 @@ impl PathBuf {

`

`1391`

`1406`

`` /// `file_name`. The new path will be a sibling of the original path.

``

`1392`

`1407`

`/// (That is, it will have the same parent.)

`

`1393`

`1408`

`///

`

``

`1409`

`+

/// The argument is not sanitized, so can include separators. This

`

``

`1410`

`+

/// behaviour may be changed to a panic in the future.

`

``

`1411`

`+

///

`

`1394`

`1412`

`` /// [`self.file_name`]: Path::file_name

``

`1395`

`1413`

`` /// [`pop`]: PathBuf::pop

``

`1396`

`1414`

`///

`

`@@ -1411,6 +1429,12 @@ impl PathBuf {

`

`1411`

`1429`

`///

`

`1412`

`1430`

`/// buf.set_file_name("baz");

`

`1413`

`1431`

`/// assert!(buf == PathBuf::from("/baz"));

`

``

`1432`

`+

///

`

``

`1433`

`+

/// buf.set_file_name("../b/c.txt");

`

``

`1434`

`+

/// assert!(buf == PathBuf::from("/../b/c.txt"));

`

``

`1435`

`+

///

`

``

`1436`

`+

/// buf.set_file_name("baz");

`

``

`1437`

`+

/// assert!(buf == PathBuf::from("/../b/baz"));

`

`1414`

`1438`

```` /// ```

1415

1439

`#[stable(feature = "rust1", since = "1.0.0")]

`

1416

1440

`pub fn set_file_name<S: AsRef>(&mut self, file_name: S) {

`