|
72 | 72 | //!
|
73 | 73 | //! * **From Rust to C:** [`CString`] represents an owned, C-friendly
|
74 | 74 | //! string: it is nul-terminated, and has no internal nul characters.
|
75 |
| -//! Rust code can create a `CString` out of a normal string (provided |
| 75 | +//! Rust code can create a [`CString`] out of a normal string (provided |
76 | 76 | //! that the string doesn't have nul characters in the middle), and
|
77 |
| -//! then use a variety of methods to obtain a raw `*mut u8` that can |
| 77 | +//! then use a variety of methods to obtain a raw `*mut `[`u8`] that can |
78 | 78 | //! then be passed as an argument to functions which use the C
|
79 | 79 | //! conventions for strings.
|
80 | 80 | //!
|
81 | 81 | //! * **From C to Rust:** [`CStr`] represents a borrowed C string; it
|
82 |
| -//! is what you would use to wrap a raw `*const u8` that you got from |
83 |
| -//! a C function. A `CStr` is guaranteed to be a nul-terminated array |
84 |
| -//! of bytes. Once you have a `CStr`, you can convert it to a Rust |
85 |
| -//! `&str` if it's valid UTF-8, or lossily convert it by adding |
| 82 | +//! is what you would use to wrap a raw `*const `[`u8`] that you got from |
| 83 | +//! a C function. A [`CStr`] is guaranteed to be a nul-terminated array |
| 84 | +//! of bytes. Once you have a [`CStr`], you can convert it to a Rust |
| 85 | +//! [`&str`][`str`] if it's valid UTF-8, or lossily convert it by adding |
86 | 86 | //! replacement characters.
|
87 | 87 | //!
|
88 | 88 | //! [`OsString`] and [`OsStr`] are useful when you need to transfer
|
89 | 89 | //! strings to and from the operating system itself, or when capturing
|
90 |
| -//! the output of external commands. Conversions between `OsString`, |
91 |
| -//! `OsStr` and Rust strings work similarly to those for [`CString`] |
| 90 | +//! the output of external commands. Conversions between [`OsString`], |
| 91 | +//! [`OsStr`] and Rust strings work similarly to those for [`CString`] |
92 | 92 | //! and [`CStr`].
|
93 | 93 | //!
|
94 | 94 | //! * [`OsString`] represents an owned string in whatever
|
95 | 95 | //! representation the operating system prefers. In the Rust standard
|
96 | 96 | //! library, various APIs that transfer strings to/from the operating
|
97 |
| -//! system use `OsString` instead of plain strings. For example, |
| 97 | +//! system use [`OsString`] instead of plain strings. For example, |
98 | 98 | //! [`env::var_os()`] is used to query environment variables; it
|
99 |
| -//! returns an `Option<OsString>`. If the environment variable exists |
100 |
| -//! you will get a `Some(os_string)`, which you can *then* try to |
| 99 | +//! returns an [`Option`]`<`[`OsString`]`>`. If the environment variable |
| 100 | +//! exists you will get a [`Some`]`(os_string)`, which you can *then* try to |
101 | 101 | //! convert to a Rust string. This yields a [`Result<>`], so that
|
102 | 102 | //! your code can detect errors in case the environment variable did
|
103 | 103 | //! not in fact contain valid Unicode data.
|
104 | 104 | //!
|
105 | 105 | //! * [`OsStr`] represents a borrowed reference to a string in a
|
106 | 106 | //! format that can be passed to the operating system. It can be
|
107 | 107 | //! converted into an UTF-8 Rust string slice in a similar way to
|
108 |
| -//! `OsString`. |
| 108 | +//! [`OsString`]. |
109 | 109 | //!
|
110 | 110 | //! # Conversions
|
111 | 111 | //!
|
|
131 | 131 | //! Additionally, on Windows [`OsString`] implements the
|
132 | 132 | //! `std::os::windows:ffi::`[`OsStringExt`][windows.OsStringExt]
|
133 | 133 | //! trait, which provides a [`from_wide`] method. The result of this
|
134 |
| -//! method is an `OsString` which can be round-tripped to a Windows |
| 134 | +//! method is an [`OsString`] which can be round-tripped to a Windows |
135 | 135 | //! string losslessly.
|
136 | 136 | //!
|
137 | 137 | //! [`String`]: ../string/struct.String.html
|
|
160 | 160 | //! [`collect`]: ../iter/trait.Iterator.html#method.collect
|
161 | 161 | //! [windows.OsStringExt]: ../os/windows/ffi/trait.OsStringExt.html
|
162 | 162 | //! [`from_wide`]: ../os/windows/ffi/trait.OsStringExt.html#tymethod.from_wide
|
| 163 | +//! [`Option`]: ../option/enum.Option.html |
| 164 | +//! [`Some`]: ../option/enum.Option.html#variant.Some |
163 | 165 |
|
164 | 166 | #![stable(feature = "rust1", since = "1.0.0")]
|
165 | 167 |
|
|
0 commit comments