about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-04-09 09:17:34 +0000
committerbors <bors@rust-lang.org>2017-04-09 09:17:34 +0000
commitebb10a6131834e14f0685ef399b531444d631e9c (patch)
tree16a884068513cff9b9352a713c2aff7d74f3c15b
parentcff81da514068ea89e06d1a62357971d34094ea3 (diff)
parent68909b0ec0d8738a8f1a0bb7a80998a246943471 (diff)
downloadrust-ebb10a6131834e14f0685ef399b531444d631e9c.tar.gz
rust-ebb10a6131834e14f0685ef399b531444d631e9c.zip
Auto merge of #41095 - clarcharr:as_extras, r=alexcrichton
Add as_c_str

Again, tying up some consistencies with `CString`.
-rw-r--r--src/doc/unstable-book/src/SUMMARY.md1
-rw-r--r--src/doc/unstable-book/src/as-c-str.md8
-rw-r--r--src/libstd/ffi/c_str.rs6
3 files changed, 15 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md
index 93ce911ac6c..d86766bac02 100644
--- a/src/doc/unstable-book/src/SUMMARY.md
+++ b/src/doc/unstable-book/src/SUMMARY.md
@@ -12,6 +12,7 @@
 - [alloc_system](alloc-system.md)
 - [allocator](allocator.md)
 - [allow_internal_unstable](allow-internal-unstable.md)
+- [as_c_str](as-c-str.md)
 - [as_unsafe_cell](as-unsafe-cell.md)
 - [ascii_ctype](ascii-ctype.md)
 - [asm](asm.md)
diff --git a/src/doc/unstable-book/src/as-c-str.md b/src/doc/unstable-book/src/as-c-str.md
new file mode 100644
index 00000000000..ed32eedb348
--- /dev/null
+++ b/src/doc/unstable-book/src/as-c-str.md
@@ -0,0 +1,8 @@
+# `as_c_str`
+
+The tracking issue for this feature is: [#40380]
+
+[#40380]: https://github.com/rust-lang/rust/issues/40380
+
+------------------------
+
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index fc1b9a97632..29f977ecd8c 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -324,6 +324,12 @@ impl CString {
         &self.inner
     }
 
+    /// Extracts a `CStr` slice containing the entire string.
+    #[unstable(feature = "as_c_str", issue = "40380")]
+    pub fn as_c_str(&self) -> &CStr {
+        &*self
+    }
+
     /// Converts this `CString` into a boxed `CStr`.
     #[unstable(feature = "into_boxed_c_str", issue = "40380")]
     pub fn into_boxed_c_str(self) -> Box<CStr> {