about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-12-03 18:07:06 +0800
committerGitHub <noreply@github.com>2018-12-03 18:07:06 +0800
commite9a805522c7cee40fdc88edfb7a6ae05c2ad1752 (patch)
treef66deeca2d765c9caf9a68bca4db28f057806078 /src/libstd/ffi
parent25c375413ab8e24b01bef1d80d61dff58ef7bc1c (diff)
parenta1e9c7fc2e4806fe72c84178bf1116f645d18c43 (diff)
downloadrust-e9a805522c7cee40fdc88edfb7a6ae05c2ad1752.tar.gz
rust-e9a805522c7cee40fdc88edfb7a6ae05c2ad1752.zip
Rollup merge of #56141 - jnqnfe:osstr_len_clarity, r=nagisa
[std] Osstr len clarity
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/os_str.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs
index e9390630445..0edfd122cef 100644
--- a/src/libstd/ffi/os_str.rs
+++ b/src/libstd/ffi/os_str.rs
@@ -42,6 +42,13 @@ use sys_common::{AsInner, IntoInner, FromInner};
 /// in each pair are owned strings; the latter are borrowed
 /// references.
 ///
+/// Note, `OsString` and `OsStr` internally do not necessarily hold strings in
+/// the form native to the platform; While on Unix, strings are stored as a
+/// sequence of 8-bit values, on Windows, where strings are 16-bit value based
+/// as just discussed, strings are also actually stored as a sequence of 8-bit
+/// values, encoded in a less-strict variant of UTF-8. This is useful to
+/// understand when handling capacity and length values.
+///
 /// # Creating an `OsString`
 ///
 /// **From a Rust string**: `OsString` implements
@@ -583,14 +590,19 @@ impl OsStr {
 
     /// Returns the length of this `OsStr`.
     ///
-    /// Note that this does **not** return the number of bytes in this string
-    /// as, for example, OS strings on Windows are encoded as a list of [`u16`]
-    /// rather than a list of bytes. This number is simply useful for passing to
-    /// other methods like [`OsString::with_capacity`] to avoid reallocations.
+    /// Note that this does **not** return the number of bytes in the string in
+    /// OS string form.
+    ///
+    /// The length returned is that of the underlying storage used by `OsStr`;
+    /// As discussed in the [`OsString`] introduction, [`OsString`] and `OsStr`
+    /// store strings in a form best suited for cheap inter-conversion between
+    /// native-platform and Rust string forms, which may differ significantly
+    /// from both of them, including in storage size and encoding.
     ///
-    /// See `OsStr` introduction for more information about encoding.
+    /// This number is simply useful for passing to other methods, like
+    /// [`OsString::with_capacity`] to avoid reallocations.
     ///
-    /// [`u16`]: ../primitive.u16.html
+    /// [`OsString`]: struct.OsString.html
     /// [`OsString::with_capacity`]: struct.OsString.html#method.with_capacity
     ///
     /// # Examples