diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-01-04 22:47:23 -0500 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2017-01-05 09:52:14 -0500 |
| commit | 4794f956839328cd813aceb2cba545c9318d4895 (patch) | |
| tree | ea31ffb777d275926e1c12da5eacf20112fbc2c5 /src/libstd/ffi | |
| parent | 7b659cfdbce094a790dbb246da2681a47565782a (diff) | |
| download | rust-4794f956839328cd813aceb2cba545c9318d4895.tar.gz rust-4794f956839328cd813aceb2cba545c9318d4895.zip | |
Expand {Path,OsStr}::{to_str,to_string_lossy} doc examples.
Diffstat (limited to 'src/libstd/ffi')
| -rw-r--r-- | src/libstd/ffi/os_str.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 84b50f04463..175fe30db66 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -259,6 +259,15 @@ impl OsStr { /// Yields a `&str` slice if the `OsStr` is valid Unicode. /// /// This conversion may entail doing a check for UTF-8 validity. + /// + /// # Examples + /// + /// ``` + /// use std::ffi::OsStr; + /// + /// let os_str = OsStr::new("foo"); + /// assert_eq!(os_str.to_str(), Some("foo")); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn to_str(&self) -> Option<&str> { self.inner.to_str() @@ -267,6 +276,20 @@ impl OsStr { /// Converts an `OsStr` to a `Cow<str>`. /// /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. + /// + /// # Examples + /// + /// Calling `to_string_lossy` on an `OsStr` with valid unicode: + /// + /// ``` + /// use std::ffi::OsStr; + /// + /// let os_str = OsStr::new("foo"); + /// assert_eq!(os_str.to_string_lossy(), "foo"); + /// ``` + /// + /// Had `os_str` contained invalid unicode, the `to_string_lossy` call might + /// have returned `"fo�"`. #[stable(feature = "rust1", since = "1.0.0")] pub fn to_string_lossy(&self) -> Cow<str> { self.inner.to_string_lossy() |
