From 68909b0ec0d8738a8f1a0bb7a80998a246943471 Mon Sep 17 00:00:00 2001 From: Clar Charr Date: Wed, 5 Apr 2017 17:13:46 -0400 Subject: [PATCH] Add as_c_str. --- src/doc/unstable-book/src/SUMMARY.md | 1 + src/doc/unstable-book/src/as-c-str.md | 8 ++++++++ src/libstd/ffi/c_str.rs | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 src/doc/unstable-book/src/as-c-str.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 9ce097e78a4e5..1f2ef3669b84e 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 0000000000000..ed32eedb3481e --- /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 2d14bb66bf4f9..d157d52259d2e 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 {