Skip to content

Commit 32132d9

Browse files
author
lukaramu
committed
Expand std::path::Display's docs
Part of #29368. * Added explanation for why the struct exists * Added link to where it is created * Added example
1 parent 51ca5fe commit 32132d9

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/libstd/path.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,26 @@ impl fmt::Debug for Path {
22362236
}
22372237
}
22382238

2239-
/// Helper struct for safely printing paths with `format!()` and `{}`
2239+
/// Helper struct for safely printing paths with [`format!`] and `{}`.
2240+
///
2241+
/// A [`Path`] might contain non-Unicode data. This `struct` implements the
2242+
/// [`Display`] trait in a way that mitigates that. It is created by the
2243+
/// [`display`][`Path::display`] method on [`Path`].
2244+
///
2245+
/// # Examples
2246+
///
2247+
/// ```
2248+
/// use std::path::Path;
2249+
///
2250+
/// let path = Path::new("/tmp/foo.rs");
2251+
///
2252+
/// println!("{}", path.display());
2253+
/// ```
2254+
///
2255+
/// [`Display`]: ../../std/fmt/trait.Display.html
2256+
/// [`format!`]: ../../std/macro.format.html
2257+
/// [`Path`]: struct.Path.html
2258+
/// [`Path::display`]: struct.Path.html#method.display
22402259
#[stable(feature = "rust1", since = "1.0.0")]
22412260
pub struct Display<'a> {
22422261
path: &'a Path,

0 commit comments

Comments
 (0)