|
81 | 81 | //! [`OsStr`] and Rust strings work similarly to those for [`CString`]
|
82 | 82 | //! and [`CStr`].
|
83 | 83 | //!
|
84 |
| -//! * [`OsString`] represents an owned string in whatever |
85 |
| -//! representation the operating system prefers. In the Rust standard |
86 |
| -//! library, various APIs that transfer strings to/from the operating |
| 84 | +//! * [`OsString`] losslessly represents an owned platform string. However, this |
| 85 | +//! representation is not necessarily in a form native to the platform. |
| 86 | +//! In the Rust standard library, various APIs that transfer strings to/from the operating |
87 | 87 | //! system use [`OsString`] instead of plain strings. For example,
|
88 | 88 | //! [`env::var_os()`] is used to query environment variables; it
|
89 | 89 | //! returns an <code>[Option]<[OsString]></code>. If the environment variable
|
|
92 | 92 | //! your code can detect errors in case the environment variable did
|
93 | 93 | //! not in fact contain valid Unicode data.
|
94 | 94 | //!
|
95 |
| -//! * [`OsStr`] represents a borrowed reference to a string in a |
96 |
| -//! format that can be passed to the operating system. It can be |
97 |
| -//! converted into a UTF-8 Rust string slice in a similar way to |
| 95 | +//! * [`OsStr`] losslessly represents a borrowed reference to a platform string. |
| 96 | +//! However, this representation is not necessarily in a form native to the platform. |
| 97 | +//! It can be converted into a UTF-8 Rust string slice in a similar way to |
98 | 98 | //! [`OsString`].
|
99 | 99 | //!
|
100 | 100 | //! # Conversions
|
|
113 | 113 | //!
|
114 | 114 | //! ## On Windows
|
115 | 115 | //!
|
| 116 | +//! An [`OsStr`] can be losslessly converted to a native Windows string. And |
| 117 | +//! a native Windows string can be losslessly converted to an [`OsString`]. |
| 118 | +//! |
116 | 119 | //! On Windows, [`OsStr`] implements the
|
117 | 120 | //! <code>std::os::windows::ffi::[OsStrExt][windows.OsStrExt]</code> trait,
|
118 | 121 | //! which provides an [`encode_wide`] method. This provides an
|
119 |
| -//! iterator that can be [`collect`]ed into a vector of [`u16`]. |
| 122 | +//! iterator that can be [`collect`]ed into a vector of [`u16`]. After a nul |
| 123 | +//! characters is appended, this is the same as a native Windows string. |
120 | 124 | //!
|
121 | 125 | //! Additionally, on Windows [`OsString`] implements the
|
122 | 126 | //! <code>std::os::windows:ffi::[OsStringExt][windows.OsStringExt]</code>
|
123 |
| -//! trait, which provides a [`from_wide`] method. The result of this |
124 |
| -//! method is an [`OsString`] which can be round-tripped to a Windows |
125 |
| -//! string losslessly. |
| 127 | +//! trait, which provides a [`from_wide`] method to convert a native Windows |
| 128 | +//! string (without the terminating nul character) to an [`OsString`]. |
126 | 129 | //!
|
127 | 130 | //! [Unicode scalar value]: https://www.unicode.org/glossary/#unicode_scalar_value
|
128 | 131 | //! [Unicode code point]: https://www.unicode.org/glossary/#code_point
|
|
0 commit comments