@@ -20,11 +20,38 @@ use sys_common::{FromInner, IntoInner, AsInner};
2020/// Unix-specific extensions to `OsString`.
2121#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2222pub trait OsStringExt {
23- /// Creates an `OsString` from a byte vector.
23+ /// Creates an [`OsString`] from a byte vector.
24+ ///
25+ /// # Examples
26+ ///
27+ /// ```
28+ /// use std::ffi::OsString;
29+ /// use std::os::unix::ffi::OsStringExt;
30+ ///
31+ /// let bytes = b"foo".to_vec();
32+ /// let os_string = OsString::from_vec(bytes);
33+ /// assert_eq!(os_string.to_str(), Some("foo"));
34+ /// ```
35+ ///
36+ /// [`OsString`]: ../../../ffi/struct.OsString.html
2437 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2538 fn from_vec ( vec : Vec < u8 > ) -> Self ;
2639
27- /// Yields the underlying byte vector of this `OsString`.
40+ /// Yields the underlying byte vector of this [`OsString`].
41+ ///
42+ /// # Examples
43+ ///
44+ /// ```
45+ /// use std::ffi::OsString;
46+ /// use std::os::unix::ffi::OsStringExt;
47+ ///
48+ /// let mut os_string = OsString::new();
49+ /// os_string.push("foo");
50+ /// let bytes = os_string.into_vec();
51+ /// assert_eq!(bytes, b"foo");
52+ /// ```
53+ ///
54+ /// [`OsString`]: ../../../ffi/struct.OsString.html
2855 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2956 fn into_vec ( self ) -> Vec < u8 > ;
3057}
@@ -43,9 +70,36 @@ impl OsStringExt for OsString {
4370#[ stable( feature = "rust1" , since = "1.0.0" ) ]
4471pub trait OsStrExt {
4572 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
73+ /// Creates an [`OsStr`] from a byte slice.
74+ ///
75+ /// # Examples
76+ ///
77+ /// ```
78+ /// use std::ffi::OsStr;
79+ /// use std::os::unix::ffi::OsStrExt;
80+ ///
81+ /// let bytes = b"foo";
82+ /// let os_str = OsStr::from_bytes(bytes);
83+ /// assert_eq!(os_str.to_str(), Some("foo"));
84+ /// ```
85+ ///
86+ /// [`OsStr`]: ../../../ffi/struct.OsStr.html
4687 fn from_bytes ( slice : & [ u8 ] ) -> & Self ;
4788
48- /// Gets the underlying byte view of the `OsStr` slice.
89+ /// Gets the underlying byte view of the [`OsStr`] slice.
90+ ///
91+ /// # Examples
92+ ///
93+ /// ```
94+ /// use std::ffi::OsStr;
95+ /// use std::os::unix::ffi::OsStrExt;
96+ ///
97+ /// let mut os_str = OsStr::new("foo");
98+ /// let bytes = os_str.as_bytes();
99+ /// assert_eq!(bytes, b"foo");
100+ /// ```
101+ ///
102+ /// [`OsStr`]: ../../../ffi/struct.OsStr.html
49103 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
50104 fn as_bytes ( & self ) -> & [ u8 ] ;
51105}
0 commit comments