@@ -1247,9 +1247,10 @@ impl Path {
1247
1247
/// ```
1248
1248
/// use std::path::Path;
1249
1249
///
1250
- /// let s = String::from("bar.txt");
1251
- /// let p = Path::new(&s);
1252
- /// Path::new(&p);
1250
+ /// let string = String::from("foo.txt");
1251
+ /// let from_string = Path::new(&string);
1252
+ /// let from_path = Path::new(&from_string);
1253
+ /// assert_eq!(from_string, from_path);
1253
1254
/// ```
1254
1255
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1255
1256
pub fn new < S : AsRef < OsStr > + ?Sized > ( s : & S ) -> & Path {
@@ -1264,6 +1265,7 @@ impl Path {
1264
1265
/// use std::path::Path;
1265
1266
///
1266
1267
/// let os_str = Path::new("foo.txt").as_os_str();
1268
+ /// assert_eq!(os_str, std::ffi::OsStr::new("foo.txt"));
1267
1269
/// ```
1268
1270
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1269
1271
pub fn as_os_str ( & self ) -> & OsStr {
@@ -1280,6 +1282,7 @@ impl Path {
1280
1282
/// use std::path::Path;
1281
1283
///
1282
1284
/// let path_str = Path::new("foo.txt").to_str();
1285
+ //// assert_eq!(path_str, Some("foo.txt"));
1283
1286
/// ```
1284
1287
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1285
1288
pub fn to_str ( & self ) -> Option < & str > {
@@ -1296,6 +1299,7 @@ impl Path {
1296
1299
/// use std::path::Path;
1297
1300
///
1298
1301
/// let path_str = Path::new("foo.txt").to_string_lossy();
1302
+ /// assert_eq!(path_str, "foo.txt");
1299
1303
/// ```
1300
1304
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1301
1305
pub fn to_string_lossy ( & self ) -> Cow < str > {
@@ -1309,7 +1313,8 @@ impl Path {
1309
1313
/// ```
1310
1314
/// use std::path::Path;
1311
1315
///
1312
- /// let path_str = Path::new("foo.txt").to_path_buf();
1316
+ /// let path_buf = Path::new("foo.txt").to_path_buf();
1317
+ /// assert_eq!(path_buf, std::path::PathBuf::from("foo.txt"));
1313
1318
/// ```
1314
1319
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1315
1320
pub fn to_path_buf ( & self ) -> PathBuf {
@@ -1330,7 +1335,7 @@ impl Path {
1330
1335
/// ```
1331
1336
/// use std::path::Path;
1332
1337
///
1333
- /// assert_eq!(false, Path::new("foo.txt").is_absolute());
1338
+ /// assert!(! Path::new("foo.txt").is_absolute());
1334
1339
/// ```
1335
1340
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1336
1341
pub fn is_absolute ( & self ) -> bool {
@@ -1393,14 +1398,12 @@ impl Path {
1393
1398
/// use std::path::Path;
1394
1399
///
1395
1400
/// let path = Path::new("/foo/bar");
1396
- /// let foo = path.parent().unwrap();
1401
+ /// let parent = path.parent().unwrap();
1402
+ /// assert_eq!(parent, Path::new("/foo"));
1397
1403
///
1398
- /// assert!(foo == Path::new("/foo"));
1399
- ///
1400
- /// let root = foo.parent().unwrap();
1401
- ///
1402
- /// assert!(root == Path::new("/"));
1403
- /// assert!(root.parent() == None);
1404
+ /// let grand_parent = parent.parent().unwrap();
1405
+ /// assert_eq!(grand_parent, Path::new("/"));
1406
+ /// assert_eq!(grand_parent.parent(), None);
1404
1407
/// ```
1405
1408
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1406
1409
pub fn parent ( & self ) -> Option < & Path > {
@@ -1416,18 +1419,19 @@ impl Path {
1416
1419
1417
1420
/// The final component of the path, if it is a normal file.
1418
1421
///
1419
- /// If the path terminates in `.`, `..`, or consists solely or a root of
1422
+ /// If the path terminates in `.`, `..`, or consists solely of a root of
1420
1423
/// prefix, `file_name` will return `None`.
1421
1424
///
1422
1425
/// # Examples
1423
1426
///
1424
1427
/// ```
1425
1428
/// use std::path::Path;
1429
+ /// use std::ffi::OsStr;
1426
1430
///
1427
- /// let path = Path::new("hello_world.rs ");
1428
- /// let filename = "hello_world.rs" ;
1431
+ /// let path = Path::new("foo.txt ");
1432
+ /// let os_str = OsStr::new("foo.txt") ;
1429
1433
///
1430
- /// assert_eq!(filename , path.file_name().unwrap ());
1434
+ /// assert_eq!(Some(os_str) , path.file_name());
1431
1435
/// ```
1432
1436
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1433
1437
pub fn file_name ( & self ) -> Option < & OsStr > {
@@ -1538,11 +1542,9 @@ impl Path {
1538
1542
/// # Examples
1539
1543
///
1540
1544
/// ```
1541
- /// use std::path::Path;
1542
- ///
1543
- /// let path = Path::new("/tmp");
1545
+ /// use std::path::{Path, PathBuf};
1544
1546
///
1545
- /// let new_path = path .join("foo" );
1547
+ /// assert_eq!(Path::new("/etc") .join("passwd"), PathBuf::from("/etc/passwd") );
1546
1548
/// ```
1547
1549
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1548
1550
pub fn join < P : AsRef < Path > > ( & self , path : P ) -> PathBuf {
@@ -1558,11 +1560,10 @@ impl Path {
1558
1560
/// # Examples
1559
1561
///
1560
1562
/// ```
1561
- /// use std::path::Path;
1562
- ///
1563
- /// let path = Path::new("/tmp/foo.rs");
1563
+ /// use std::path::{Path, PathBuf};
1564
1564
///
1565
- /// let new_path = path.with_file_name("bar.rs");
1565
+ /// let path = Path::new("/tmp/foo.txt");
1566
+ /// assert_eq!(path.with_file_name("bar.txt"), PathBuf::from("/tmp/bar.txt"));
1566
1567
/// ```
1567
1568
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1568
1569
pub fn with_file_name < S : AsRef < OsStr > > ( & self , file_name : S ) -> PathBuf {
@@ -1580,10 +1581,8 @@ impl Path {
1580
1581
/// ```
1581
1582
/// use std::path::{Path, PathBuf};
1582
1583
///
1583
- /// let path = Path::new("/tmp/foo.rs");
1584
- ///
1585
- /// let new_path = path.with_extension("txt");
1586
- /// assert_eq!(new_path, PathBuf::from("/tmp/foo.txt"));
1584
+ /// let path = Path::new("foo.rs");
1585
+ /// assert_eq!(path.with_extension("txt"), PathBuf::from("foo.txt"));
1587
1586
/// ```
1588
1587
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1589
1588
pub fn with_extension < S : AsRef < OsStr > > ( & self , extension : S ) -> PathBuf {
@@ -1597,13 +1596,15 @@ impl Path {
1597
1596
/// # Examples
1598
1597
///
1599
1598
/// ```
1600
- /// use std::path::Path;
1599
+ /// use std::path::{Path, Component};
1600
+ /// use std::ffi::OsStr;
1601
1601
///
1602
- /// let path = Path::new("/tmp/foo.rs" );
1602
+ /// let mut components = Path::new("/tmp/foo.txt").components( );
1603
1603
///
1604
- /// for component in path.components() {
1605
- /// println!("{:?}", component);
1606
- /// }
1604
+ /// assert_eq!(components.next(), Some(Component::RootDir));
1605
+ /// assert_eq!(components.next(), Some(Component::Normal(OsStr::new("tmp"))));
1606
+ /// assert_eq!(components.next(), Some(Component::Normal(OsStr::new("foo.txt"))));
1607
+ /// assert_eq!(components.next(), None)
1607
1608
/// ```
1608
1609
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1609
1610
pub fn components ( & self ) -> Components {
@@ -1622,13 +1623,14 @@ impl Path {
1622
1623
/// # Examples
1623
1624
///
1624
1625
/// ```
1625
- /// use std::path::Path;
1626
- ///
1627
- /// let path = Path::new("/tmp/foo.rs");
1628
- ///
1629
- /// for component in path.iter() {
1630
- /// println!("{:?}", component);
1631
- /// }
1626
+ /// use std::path::{self, Path};
1627
+ /// use std::ffi::OsStr;
1628
+ ///
1629
+ /// let mut it = Path::new("/tmp/foo.txt").iter();
1630
+ /// assert_eq!(it.next(), Some(OsStr::new(&path::MAIN_SEPARATOR.to_string())));
1631
+ /// assert_eq!(it.next(), Some(OsStr::new("tmp")));
1632
+ /// assert_eq!(it.next(), Some(OsStr::new("foo.txt")));
1633
+ /// assert_eq!(it.next(), None)
1632
1634
/// ```
1633
1635
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1634
1636
pub fn iter ( & self ) -> Iter {
0 commit comments