Skip to content

Commit d7a5390

Browse files
Rollup merge of rust-lang#41870 - excaliburHisSheath:iss29367-windows-docs, r=frewsxcv
Improve docs in os::windows::ffi and os::windows::fs Part of rust-lang#29367 This PR makes changes to the documentation in `os::windows::ffi` and `os::windows::fs` with the goal of fleshing them out and bringing them in line with Rust's quality standards. r? @steveklabnik
2 parents b21577e + a892925 commit d7a5390

File tree

4 files changed

+287
-57
lines changed

4 files changed

+287
-57
lines changed

src/libstd/sys/windows/ext/ffi.rs

+37-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,22 @@ pub trait OsStringExt {
2626
/// Creates an `OsString` from a potentially ill-formed UTF-16 slice of
2727
/// 16-bit code units.
2828
///
29-
/// This is lossless: calling `.encode_wide()` on the resulting string
29+
/// This is lossless: calling [`encode_wide`] on the resulting string
3030
/// will always return the original code units.
31+
///
32+
/// # Examples
33+
///
34+
/// ```
35+
/// use std::ffi::OsString;
36+
/// use std::os::windows::prelude::*;
37+
///
38+
/// // UTF-16 encoding for "Unicode".
39+
/// let source = [0x0055, 0x006E, 0x0069, 0x0063, 0x006F, 0x0064, 0x0065];
40+
///
41+
/// let string = OsString::from_wide(&source[..]);
42+
/// ```
43+
///
44+
/// [`encode_wide`]: ./trait.OsStrExt.html#tymethod.encode_wide
3145
#[stable(feature = "rust1", since = "1.0.0")]
3246
fn from_wide(wide: &[u16]) -> Self;
3347
}
@@ -42,11 +56,29 @@ impl OsStringExt for OsString {
4256
/// Windows-specific extensions to `OsStr`.
4357
#[stable(feature = "rust1", since = "1.0.0")]
4458
pub trait OsStrExt {
45-
/// Re-encodes an `OsStr` as a wide character sequence,
46-
/// i.e. potentially ill-formed UTF-16.
59+
/// Re-encodes an `OsStr` as a wide character sequence, i.e. potentially
60+
/// ill-formed UTF-16.
61+
///
62+
/// This is lossless: calling [`OsString::from_wide`] and then
63+
/// `encode_wide` on the result will yield the original code units.
64+
/// Note that the encoding does not add a final null terminator.
65+
///
66+
/// # Examples
67+
///
68+
/// ```
69+
/// use std::ffi::OsString;
70+
/// use std::os::windows::prelude::*;
71+
///
72+
/// // UTF-16 encoding for "Unicode".
73+
/// let source = [0x0055, 0x006E, 0x0069, 0x0063, 0x006F, 0x0064, 0x0065];
74+
///
75+
/// let string = OsString::from_wide(&source[..]);
76+
///
77+
/// let result: Vec<u16> = string.encode_wide().collect();
78+
/// assert_eq!(&source[..], &result[..]);
79+
/// ```
4780
///
48-
/// This is lossless. Note that the encoding does not include a final
49-
/// null.
81+
/// [`OsString::from_wide`]: ./trait.OsStringExt.html#tymethod.from_wide
5082
#[stable(feature = "rust1", since = "1.0.0")]
5183
fn encode_wide(&self) -> EncodeWide;
5284
}

0 commit comments

Comments
 (0)