@@ -370,13 +370,15 @@ pub struct PrefixComponent<'a> {
370
370
}
371
371
372
372
impl < ' a > PrefixComponent < ' a > {
373
- /// The parsed prefix data.
373
+ /// Returns the parsed prefix data.
374
374
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
375
375
pub fn kind ( & self ) -> Prefix < ' a > {
376
376
self . parsed
377
377
}
378
378
379
- /// The raw `OsStr` slice for this prefix.
379
+ /// Returns the raw [`OsStr`] slice for this prefix.
380
+ ///
381
+ /// [`OsStr`]: ../../std/ffi/struct.OsStr.html
380
382
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
381
383
pub fn as_os_str ( & self ) -> & ' a OsStr {
382
384
self . raw
@@ -446,25 +448,25 @@ pub enum Component<'a> {
446
448
#[ stable( feature = "rust1" , since = "1.0.0" ) ] PrefixComponent < ' a >
447
449
) ,
448
450
449
- /// The root directory component, appears after any prefix and before anything else
451
+ /// The root directory component, appears after any prefix and before anything else.
450
452
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
451
453
RootDir ,
452
454
453
- /// A reference to the current directory, i.e. `.`
455
+ /// A reference to the current directory, i.e. `.`.
454
456
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
455
457
CurDir ,
456
458
457
- /// A reference to the parent directory, i.e. `..`
459
+ /// A reference to the parent directory, i.e. `..`.
458
460
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
459
461
ParentDir ,
460
462
461
- /// A normal component, i.e. `a` and `b` in `a/b`
463
+ /// A normal component, e.g. `a` and `b` in `a/b`.
462
464
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
463
465
Normal ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] & ' a OsStr ) ,
464
466
}
465
467
466
468
impl < ' a > Component < ' a > {
467
- /// Extracts the underlying `OsStr` slice.
469
+ /// Extracts the underlying [ `OsStr`] slice.
468
470
///
469
471
/// # Examples
470
472
///
@@ -475,6 +477,8 @@ impl<'a> Component<'a> {
475
477
/// let components: Vec<_> = path.components().map(|comp| comp.as_os_str()).collect();
476
478
/// assert_eq!(&components, &[".", "tmp", "foo", "bar.txt"]);
477
479
/// ```
480
+ ///
481
+ /// [`OsStr`]: ../../std/ffi/struct.OsStr.html
478
482
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
479
483
pub fn as_os_str ( self ) -> & ' a OsStr {
480
484
match self {
@@ -494,12 +498,10 @@ impl<'a> AsRef<OsStr> for Component<'a> {
494
498
}
495
499
}
496
500
497
- /// The core iterator giving the components of a path .
501
+ /// An interator over the [`Component`]s of a [`Path`] .
498
502
///
499
- /// See the module documentation for an in-depth explanation of components and
500
- /// their role in the API.
501
- ///
502
- /// This `struct` is created by the [`path::Path::components`] method.
503
+ /// This `struct` is created by the [`components`] method on [`Path`].
504
+ /// See its documentation for more.
503
505
///
504
506
/// # Examples
505
507
///
@@ -513,7 +515,9 @@ impl<'a> AsRef<OsStr> for Component<'a> {
513
515
/// }
514
516
/// ```
515
517
///
516
- /// [`path::Path::components`]: struct.Path.html#method.components
518
+ /// [`Component`]: enum.Component.html
519
+ /// [`components`]: struct.Path.html#method.components
520
+ /// [`Path`]: struct.Path.html
517
521
#[ derive( Clone ) ]
518
522
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
519
523
pub struct Components < ' a > {
@@ -534,9 +538,15 @@ pub struct Components<'a> {
534
538
back : State ,
535
539
}
536
540
537
- /// An iterator over the components of a path , as [`OsStr`] slices.
541
+ /// An iterator over the [`Component`]s of a [`Path`] , as [`OsStr`] slices.
538
542
///
543
+ /// This `struct` is created by the [`iter`] method on [`Path`].
544
+ /// See its documentation for more.
545
+ ///
546
+ /// [`Component`]: enum.Component.html
547
+ /// [`iter`]: struct.Path.html#method.iter
539
548
/// [`OsStr`]: ../../std/ffi/struct.OsStr.html
549
+ /// [`Path`]: struct.Path.html
540
550
#[ derive( Clone ) ]
541
551
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
542
552
pub struct Iter < ' a > {
@@ -762,6 +772,18 @@ impl<'a> fmt::Debug for Iter<'a> {
762
772
763
773
impl < ' a > Iter < ' a > {
764
774
/// Extracts a slice corresponding to the portion of the path remaining for iteration.
775
+ ///
776
+ /// # Examples
777
+ ///
778
+ /// ```
779
+ /// use std::path::Path;
780
+ ///
781
+ /// let mut iter = Path::new("/tmp/foo/bar.txt").iter();
782
+ /// iter.next();
783
+ /// iter.next();
784
+ ///
785
+ /// assert_eq!(Path::new("foo/bar.txt"), iter.as_path());
786
+ /// ```
765
787
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
766
788
pub fn as_path ( & self ) -> & ' a Path {
767
789
self . inner . as_path ( )
@@ -1067,9 +1089,10 @@ impl PathBuf {
1067
1089
1068
1090
/// Truncate `self` to [`self.parent`].
1069
1091
///
1070
- /// Returns false and does nothing if [`self.file_name`] is `None`.
1092
+ /// Returns ` false` and does nothing if [`self.file_name`] is [ `None`] .
1071
1093
/// Otherwise, returns `true`.
1072
1094
///
1095
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
1073
1096
/// [`self.parent`]: struct.PathBuf.html#method.parent
1074
1097
/// [`self.file_name`]: struct.PathBuf.html#method.file_name
1075
1098
///
@@ -1132,10 +1155,11 @@ impl PathBuf {
1132
1155
1133
1156
/// Updates [`self.extension`] to `extension`.
1134
1157
///
1135
- /// If [`self.file_name`] is `None`, does nothing and returns `false`.
1158
+ /// Returns `false` and does nothing if [`self.file_name`] is [`None`],
1159
+ /// returns `true` and updates the extension otherwise.
1136
1160
///
1137
- /// Otherwise, returns `true`; if [`self.extension`] is [`None`], the
1138
- /// extension is added; otherwise it is replaced.
1161
+ /// If [`self.extension`] is [`None`], the extension is added; otherwise
1162
+ /// it is replaced.
1139
1163
///
1140
1164
/// [`self.file_name`]: struct.PathBuf.html#method.file_name
1141
1165
/// [`self.extension`]: struct.PathBuf.html#method.extension
@@ -1195,7 +1219,10 @@ impl PathBuf {
1195
1219
self . inner
1196
1220
}
1197
1221
1198
- /// Converts this `PathBuf` into a boxed `Path`.
1222
+ /// Converts this `PathBuf` into a [boxed][`Box`] [`Path`].
1223
+ ///
1224
+ /// [`Box`]: ../../std/boxed/struct.Box.html
1225
+ /// [`Path`]: struct.Path.html
1199
1226
#[ unstable( feature = "into_boxed_path" , issue = "40380" ) ]
1200
1227
pub fn into_boxed_path ( self ) -> Box < Path > {
1201
1228
unsafe { mem:: transmute ( self . inner . into_boxed_os_str ( ) ) }
@@ -1402,10 +1429,14 @@ pub struct Path {
1402
1429
inner : OsStr ,
1403
1430
}
1404
1431
1405
- /// An error returned from the [`Path::strip_prefix`] method indicating that the
1406
- /// prefix was not found in `self`.
1432
+ /// An error returned from [`Path::strip_prefix`][`strip_prefix`] if the prefix
1433
+ /// was not found.
1434
+ ///
1435
+ /// This `struct` is created by the [`strip_prefix`] method on [`Path`].
1436
+ /// See its documentation for more.
1407
1437
///
1408
- /// [`Path::strip_prefix`]: struct.Path.html#method.strip_prefix
1438
+ /// [`strip_prefix`]: struct.Path.html#method.strip_prefix
1439
+ /// [`Path`]: struct.Path.html
1409
1440
#[ derive( Debug , Clone , PartialEq , Eq ) ]
1410
1441
#[ stable( since = "1.7.0" , feature = "strip_prefix" ) ]
1411
1442
pub struct StripPrefixError ( ( ) ) ;
@@ -1421,7 +1452,7 @@ impl Path {
1421
1452
os_str_as_u8_slice ( & self . inner )
1422
1453
}
1423
1454
1424
- /// Directly wrap a string slice as a `Path` slice.
1455
+ /// Directly wraps a string slice as a `Path` slice.
1425
1456
///
1426
1457
/// This is a cost-free conversion.
1427
1458
///
@@ -1525,10 +1556,11 @@ impl Path {
1525
1556
PathBuf :: from ( self . inner . to_os_string ( ) )
1526
1557
}
1527
1558
1528
- /// A path is *absolute* if it is independent of the current directory.
1559
+ /// Returns `true` if the `Path` is absolute, i.e. if it is independent of
1560
+ /// the current directory.
1529
1561
///
1530
1562
/// * On Unix, a path is absolute if it starts with the root, so
1531
- /// `is_absolute` and `has_root` are equivalent.
1563
+ /// `is_absolute` and [ `has_root`] are equivalent.
1532
1564
///
1533
1565
/// * On Windows, a path is absolute if it has a prefix and starts with the
1534
1566
/// root: `c:\windows` is absolute, while `c:temp` and `\temp` are not.
@@ -1540,14 +1572,18 @@ impl Path {
1540
1572
///
1541
1573
/// assert!(!Path::new("foo.txt").is_absolute());
1542
1574
/// ```
1575
+ ///
1576
+ /// [`has_root`]: #method.has_root
1543
1577
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1544
1578
#[ allow( deprecated) ]
1545
1579
pub fn is_absolute ( & self ) -> bool {
1546
1580
// FIXME: Remove target_os = "redox" and allow Redox prefixes
1547
1581
self . has_root ( ) && ( cfg ! ( unix) || cfg ! ( target_os = "redox" ) || self . prefix ( ) . is_some ( ) )
1548
1582
}
1549
1583
1550
- /// A path is *relative* if it is not absolute.
1584
+ /// Return `false` if the `Path` is relative, i.e. not absolute.
1585
+ ///
1586
+ /// See [`is_absolute`]'s documentation for more details.
1551
1587
///
1552
1588
/// # Examples
1553
1589
///
@@ -1556,6 +1592,8 @@ impl Path {
1556
1592
///
1557
1593
/// assert!(Path::new("foo.txt").is_relative());
1558
1594
/// ```
1595
+ ///
1596
+ /// [`is_absolute`]: #method.is_absolute
1559
1597
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1560
1598
pub fn is_relative ( & self ) -> bool {
1561
1599
!self . is_absolute ( )
@@ -1565,7 +1603,7 @@ impl Path {
1565
1603
self . components ( ) . prefix
1566
1604
}
1567
1605
1568
- /// A path has a root if the body of the path begins with the directory separator .
1606
+ /// Returns `true` if the `Path` has a root .
1569
1607
///
1570
1608
/// * On Unix, a path has a root if it begins with `/`.
1571
1609
///
@@ -1586,7 +1624,7 @@ impl Path {
1586
1624
self . components ( ) . has_root ( )
1587
1625
}
1588
1626
1589
- /// The path without its final component, if any .
1627
+ /// Returns the `Path` without its final component, if there is one .
1590
1628
///
1591
1629
/// Returns [`None`] if the path terminates in a root or prefix.
1592
1630
///
@@ -1619,9 +1657,9 @@ impl Path {
1619
1657
} )
1620
1658
}
1621
1659
1622
- /// The final component of the path , if it is a normal file.
1660
+ /// Returns the final component of the `Path` , if it is a normal file.
1623
1661
///
1624
- /// If the path terminates in `..`, `file_name` will return [`None`] .
1662
+ /// Returns [`None`] If the path terminates in `..`.
1625
1663
///
1626
1664
/// [`None`]: ../../std/option/enum.Option.html#variant.None
1627
1665
///
@@ -1631,18 +1669,7 @@ impl Path {
1631
1669
/// use std::path::Path;
1632
1670
/// use std::ffi::OsStr;
1633
1671
///
1634
- /// let path = Path::new("foo.txt");
1635
- /// let os_str = OsStr::new("foo.txt");
1636
- ///
1637
- /// assert_eq!(Some(os_str), path.file_name());
1638
- /// ```
1639
- ///
1640
- /// # Other examples
1641
- ///
1642
- /// ```
1643
- /// use std::path::Path;
1644
- /// use std::ffi::OsStr;
1645
- ///
1672
+ /// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt").file_name());
1646
1673
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.").file_name());
1647
1674
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.//").file_name());
1648
1675
/// assert_eq!(None, Path::new("foo.txt/..").file_name());
@@ -1869,7 +1896,7 @@ impl Path {
1869
1896
buf
1870
1897
}
1871
1898
1872
- /// Produce an iterator over the components of the path.
1899
+ /// Produces an iterator over the components of the path.
1873
1900
///
1874
1901
/// # Examples
1875
1902
///
@@ -1896,7 +1923,7 @@ impl Path {
1896
1923
}
1897
1924
}
1898
1925
1899
- /// Produce an iterator over the path's components viewed as [`OsStr`] slices.
1926
+ /// Produces an iterator over the path's components viewed as [`OsStr`] slices.
1900
1927
///
1901
1928
/// [`OsStr`]: ../ffi/struct.OsStr.html
1902
1929
///
@@ -1936,7 +1963,7 @@ impl Path {
1936
1963
Display { path : self }
1937
1964
}
1938
1965
1939
- /// Query the file system to get information about a file, directory, etc.
1966
+ /// Queries the file system to get information about a file, directory, etc.
1940
1967
///
1941
1968
/// This function will traverse symbolic links to query information about the
1942
1969
/// destination file.
@@ -1959,7 +1986,7 @@ impl Path {
1959
1986
fs:: metadata ( self )
1960
1987
}
1961
1988
1962
- /// Query the metadata about a file without following symlinks.
1989
+ /// Queries the metadata about a file without following symlinks.
1963
1990
///
1964
1991
/// This is an alias to [`fs::symlink_metadata`].
1965
1992
///
@@ -2096,7 +2123,11 @@ impl Path {
2096
2123
fs:: metadata ( self ) . map ( |m| m. is_dir ( ) ) . unwrap_or ( false )
2097
2124
}
2098
2125
2099
- /// Converts a `Box<Path>` into a `PathBuf` without copying or allocating.
2126
+ /// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
2127
+ /// allocating.
2128
+ ///
2129
+ /// [`Box`]: ../../std/boxed/struct.Box.html
2130
+ /// [`PathBuf`]: struct.PathBuf.html
2100
2131
#[ unstable( feature = "into_boxed_path" , issue = "40380" ) ]
2101
2132
pub fn into_path_buf ( self : Box < Path > ) -> PathBuf {
2102
2133
let inner: Box < OsStr > = unsafe { mem:: transmute ( self ) } ;
0 commit comments