Expand {Path,OsStr}::{to_str,to_string_lossy} doc examples.
This commit is contained in:
parent
7b659cfdbc
commit
4794f95683
2 changed files with 32 additions and 4 deletions
|
@ -259,6 +259,15 @@ impl OsStr {
|
||||||
/// Yields a `&str` slice if the `OsStr` is valid Unicode.
|
/// Yields a `&str` slice if the `OsStr` is valid Unicode.
|
||||||
///
|
///
|
||||||
/// This conversion may entail doing a check for UTF-8 validity.
|
/// 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")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn to_str(&self) -> Option<&str> {
|
pub fn to_str(&self) -> Option<&str> {
|
||||||
self.inner.to_str()
|
self.inner.to_str()
|
||||||
|
@ -267,6 +276,20 @@ impl OsStr {
|
||||||
/// Converts an `OsStr` to a `Cow<str>`.
|
/// Converts an `OsStr` to a `Cow<str>`.
|
||||||
///
|
///
|
||||||
/// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
|
/// 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<66>"`.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn to_string_lossy(&self) -> Cow<str> {
|
pub fn to_string_lossy(&self) -> Cow<str> {
|
||||||
self.inner.to_string_lossy()
|
self.inner.to_string_lossy()
|
||||||
|
|
|
@ -1428,8 +1428,8 @@ impl Path {
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::path::Path;
|
/// use std::path::Path;
|
||||||
///
|
///
|
||||||
/// let path_str = Path::new("foo.txt").to_str();
|
/// let path = Path::new("foo.txt");
|
||||||
/// assert_eq!(path_str, Some("foo.txt"));
|
/// assert_eq!(path.to_str(), Some("foo.txt"));
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn to_str(&self) -> Option<&str> {
|
pub fn to_str(&self) -> Option<&str> {
|
||||||
|
@ -1444,12 +1444,17 @@ impl Path {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
/// Calling `to_string_lossy` on a `Path` with valid unicode:
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::path::Path;
|
/// use std::path::Path;
|
||||||
///
|
///
|
||||||
/// let path_str = Path::new("foo.txt").to_string_lossy();
|
/// let path = Path::new("foo.txt");
|
||||||
/// assert_eq!(path_str, "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<66>.txt"`.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn to_string_lossy(&self) -> Cow<str> {
|
pub fn to_string_lossy(&self) -> Cow<str> {
|
||||||
self.inner.to_string_lossy()
|
self.inner.to_string_lossy()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue