Skip to content

Commit 478c0d1

Browse files
authored
Auto merge of #37774 - frewsxcv:path-doc-example, r=brson
Update top-level path doc examples to show results. None
2 parents d88d064 + af1aa1b commit 478c0d1

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/libstd/path.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@
2525
//!
2626
//! ```rust
2727
//! use std::path::Path;
28+
//! use std::ffi::OsStr;
2829
//!
2930
//! let path = Path::new("/tmp/foo/bar.txt");
30-
//! let file = path.file_name();
31+
//!
32+
//! let parent = path.parent();
33+
//! assert_eq!(parent, Some(Path::new("/tmp/foo")));
34+
//!
35+
//! let file_stem = path.file_stem();
36+
//! assert_eq!(file_stem, Some(OsStr::new("bar")));
37+
//!
3138
//! let extension = path.extension();
32-
//! let parent_dir = path.parent();
39+
//! assert_eq!(extension, Some(OsStr::new("txt")));
3340
//! ```
3441
//!
3542
//! To build or modify paths, use `PathBuf`:
@@ -1319,13 +1326,19 @@ impl AsRef<OsStr> for PathBuf {
13191326
///
13201327
/// ```
13211328
/// use std::path::Path;
1329+
/// use std::ffi::OsStr;
13221330
///
13231331
/// let path = Path::new("/tmp/foo/bar.txt");
1324-
/// let file = path.file_name();
1332+
///
1333+
/// let parent = path.parent();
1334+
/// assert_eq!(parent, Some(Path::new("/tmp/foo")));
1335+
///
1336+
/// let file_stem = path.file_stem();
1337+
/// assert_eq!(file_stem, Some(OsStr::new("bar")));
1338+
///
13251339
/// let extension = path.extension();
1326-
/// let parent_dir = path.parent();
1340+
/// assert_eq!(extension, Some(OsStr::new("txt")));
13271341
/// ```
1328-
///
13291342
#[stable(feature = "rust1", since = "1.0.0")]
13301343
pub struct Path {
13311344
inner: OsStr,

0 commit comments

Comments
 (0)