Skip to content

Commit 85d214e

Browse files
Rollup merge of rust-lang#54313 - cgwalters:osstr-ref-cstr, r=joshtriplett
OsStr: Document that it's not NUL terminated I somehow got confused into thinking this was the case, but it's definitely not. Let's help the common case of people who have an `OsStr` and need to call e.g. Unix APIs.
2 parents 6a4e7bb + 993d022 commit 85d214e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/libstd/ffi/os_str.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ use sys_common::{AsInner, IntoInner, FromInner};
3434
///
3535
/// `OsString` and [`OsStr`] bridge this gap by simultaneously representing Rust
3636
/// and platform-native string values, and in particular allowing a Rust string
37-
/// to be converted into an "OS" string with no cost if possible.
37+
/// to be converted into an "OS" string with no cost if possible. A consequence
38+
/// of this is that `OsString` instances are *not* `NUL` terminated; in order
39+
/// to pass to e.g. Unix system call, you should create a [`CStr`].
3840
///
3941
/// `OsString` is to [`&OsStr`] as [`String`] is to [`&str`]: the former
4042
/// in each pair are owned strings; the latter are borrowed
@@ -65,6 +67,7 @@ use sys_common::{AsInner, IntoInner, FromInner};
6567
///
6668
/// [`OsStr`]: struct.OsStr.html
6769
/// [`&OsStr`]: struct.OsStr.html
70+
/// [`CStr`]: struct.CStr.html
6871
/// [`From`]: ../convert/trait.From.html
6972
/// [`String`]: ../string/struct.String.html
7073
/// [`&str`]: ../primitive.str.html

0 commit comments

Comments
 (0)