diff options
| author | Seo Sanghyeon <sanxiyn@gmail.com> | 2017-01-10 20:27:45 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-10 20:27:45 +0900 |
| commit | 20c7dbc9b484cd61ade7b2edba95a26ccc611a83 (patch) | |
| tree | b539a3a534528caacfe3e1664e166b72d1da87a6 /src/libstd/path.rs | |
| parent | a62f1b536eb773e2fb03bcb640766f7ac6ffffb7 (diff) | |
| parent | 4794f956839328cd813aceb2cba545c9318d4895 (diff) | |
| download | rust-20c7dbc9b484cd61ade7b2edba95a26ccc611a83.tar.gz rust-20c7dbc9b484cd61ade7b2edba95a26ccc611a83.zip | |
Rollup merge of #38839 - frewsxcv:osstr-to-str, r=GuillaumeGomez
Expand {Path,OsStr}::{to_str,to_string_lossy} doc examples.
None
Diffstat (limited to 'src/libstd/path.rs')
| -rw-r--r-- | src/libstd/path.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs index d13baea40a9..3f9bf70adde 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1428,8 +1428,8 @@ impl Path { /// ``` /// use std::path::Path; /// - /// let path_str = Path::new("foo.txt").to_str(); - /// assert_eq!(path_str, Some("foo.txt")); + /// let path = Path::new("foo.txt"); + /// assert_eq!(path.to_str(), Some("foo.txt")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn to_str(&self) -> Option<&str> { @@ -1444,12 +1444,17 @@ impl Path { /// /// # Examples /// + /// Calling `to_string_lossy` on a `Path` with valid unicode: + /// /// ``` /// use std::path::Path; /// - /// let path_str = Path::new("foo.txt").to_string_lossy(); - /// assert_eq!(path_str, "foo.txt"); + /// let path = Path::new("foo.txt"); + /// assert_eq!(path.to_string_lossy(), "foo.txt"); /// ``` + /// + /// Had `os_str` contained invalid unicode, the `to_string_lossy` call might + /// have returned `"fo�.txt"`. #[stable(feature = "rust1", since = "1.0.0")] pub fn to_string_lossy(&self) -> Cow<str> { self.inner.to_string_lossy() |
