Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[std] Osstr len clarity #56141

Merged
merged 2 commits into from
Dec 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down