]> git.lizzy.rs Git - rust.git/commitdiff
OsStr: Document that it's not NUL terminated
authorColin Walters <walters@verbum.org>
Tue, 18 Sep 2018 01:10:36 +0000 (21:10 -0400)
committerColin Walters <walters@verbum.org>
Tue, 18 Sep 2018 01:10:36 +0000 (21:10 -0400)
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.

src/libstd/ffi/os_str.rs

index 237af2f04e59d5fe9ad183e005a1adad09a2d42d..e9390630445a106fbf878479492c212778880e5f 100644 (file)
@@ -34,7 +34,9 @@
 ///
 /// `OsString` and [`OsStr`] bridge this gap by simultaneously representing Rust
 /// and platform-native string values, and in particular allowing a Rust string
-/// to be converted into an "OS" string with no cost if possible.
+/// to be converted into an "OS" string with no cost if possible.  A consequence
+/// of this is that `OsString` instances are *not* `NUL` terminated; in order
+/// to pass to e.g. Unix system call, you should create a [`CStr`].
 ///
 /// `OsString` is to [`&OsStr`] as [`String`] is to [`&str`]: the former
 /// in each pair are owned strings; the latter are borrowed
@@ -65,6 +67,7 @@
 ///
 /// [`OsStr`]: struct.OsStr.html
 /// [`&OsStr`]: struct.OsStr.html
+/// [`CStr`]: struct.CStr.html
 /// [`From`]: ../convert/trait.From.html
 /// [`String`]: ../string/struct.String.html
 /// [`&str`]: ../primitive.str.html