File tree 2 files changed +32
-4
lines changed
2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,15 @@ impl OsStr {
259
259
/// Yields a `&str` slice if the `OsStr` is valid Unicode.
260
260
///
261
261
/// This conversion may entail doing a check for UTF-8 validity.
262
+ ///
263
+ /// # Examples
264
+ ///
265
+ /// ```
266
+ /// use std::ffi::OsStr;
267
+ ///
268
+ /// let os_str = OsStr::new("foo");
269
+ /// assert_eq!(os_str.to_str(), Some("foo"));
270
+ /// ```
262
271
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
263
272
pub fn to_str ( & self ) -> Option < & str > {
264
273
self . inner . to_str ( )
@@ -267,6 +276,20 @@ impl OsStr {
267
276
/// Converts an `OsStr` to a `Cow<str>`.
268
277
///
269
278
/// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
279
+ ///
280
+ /// # Examples
281
+ ///
282
+ /// Calling `to_string_lossy` on an `OsStr` with valid unicode:
283
+ ///
284
+ /// ```
285
+ /// use std::ffi::OsStr;
286
+ ///
287
+ /// let os_str = OsStr::new("foo");
288
+ /// assert_eq!(os_str.to_string_lossy(), "foo");
289
+ /// ```
290
+ ///
291
+ /// Had `os_str` contained invalid unicode, the `to_string_lossy` call might
292
+ /// have returned `"fo�"`.
270
293
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
271
294
pub fn to_string_lossy ( & self ) -> Cow < str > {
272
295
self . inner . to_string_lossy ( )
Original file line number Diff line number Diff line change @@ -1428,8 +1428,8 @@ impl Path {
1428
1428
/// ```
1429
1429
/// use std::path::Path;
1430
1430
///
1431
- /// let path_str = Path::new("foo.txt").to_str( );
1432
- /// assert_eq!(path_str , Some("foo.txt"));
1431
+ /// let path = Path::new("foo.txt");
1432
+ /// assert_eq!(path.to_str() , Some("foo.txt"));
1433
1433
/// ```
1434
1434
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1435
1435
pub fn to_str ( & self ) -> Option < & str > {
@@ -1444,12 +1444,17 @@ impl Path {
1444
1444
///
1445
1445
/// # Examples
1446
1446
///
1447
+ /// Calling `to_string_lossy` on a `Path` with valid unicode:
1448
+ ///
1447
1449
/// ```
1448
1450
/// use std::path::Path;
1449
1451
///
1450
- /// let path_str = Path::new("foo.txt").to_string_lossy( );
1451
- /// assert_eq!(path_str , "foo.txt");
1452
+ /// let path = Path::new("foo.txt");
1453
+ /// assert_eq!(path.to_string_lossy() , "foo.txt");
1452
1454
/// ```
1455
+ ///
1456
+ /// Had `os_str` contained invalid unicode, the `to_string_lossy` call might
1457
+ /// have returned `"fo�.txt"`.
1453
1458
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1454
1459
pub fn to_string_lossy ( & self ) -> Cow < str > {
1455
1460
self . inner . to_string_lossy ( )
You can’t perform that action at this time.
0 commit comments