Skip to content

Commit 68909b0

Browse files
author
Clar Charr
committed
Add as_c_str.
1 parent 44855a4 commit 68909b0

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/doc/unstable-book/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [alloc_system](alloc-system.md)
1313
- [allocator](allocator.md)
1414
- [allow_internal_unstable](allow-internal-unstable.md)
15+
- [as_c_str](as-c-str.md)
1516
- [as_unsafe_cell](as-unsafe-cell.md)
1617
- [ascii_ctype](ascii-ctype.md)
1718
- [asm](asm.md)

src/doc/unstable-book/src/as-c-str.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# `as_c_str`
2+
3+
The tracking issue for this feature is: [#40380]
4+
5+
[#40380]: https://github.com/rust-lang/rust/issues/40380
6+
7+
------------------------
8+

src/libstd/ffi/c_str.rs

+6
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ impl CString {
324324
&self.inner
325325
}
326326

327+
/// Extracts a `CStr` slice containing the entire string.
328+
#[unstable(feature = "as_c_str", issue = "40380")]
329+
pub fn as_c_str(&self) -> &CStr {
330+
&*self
331+
}
332+
327333
/// Converts this `CString` into a boxed `CStr`.
328334
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
329335
pub fn into_boxed_c_str(self) -> Box<CStr> {

0 commit comments

Comments
 (0)