1+ //! [`CStr`] and its related types.
2+
13use crate :: cmp:: Ordering ;
24use crate :: error:: Error ;
35use crate :: ffi:: c_char;
@@ -8,15 +10,20 @@ use crate::slice;
810use crate :: slice:: memchr;
911use crate :: str;
1012
13+ // FIXME: because this is doc(inline)d, we *have* to use intra-doc links because the actual link
14+ // depends on where the item is being documented. however, since this is libcore, we can't
15+ // actually reference libstd or liballoc in intra-doc links. so, the best we can do is remove the
16+ // links to `CString` and `String` for now until a solution is developed
17+
1118/// Representation of a borrowed C string.
1219///
1320/// This type represents a borrowed reference to a nul-terminated
1421/// array of bytes. It can be constructed safely from a <code>&[[u8]]</code>
1522/// slice, or unsafely from a raw `*const c_char`. It can then be
1623/// converted to a Rust <code>&[str]</code> by performing UTF-8 validation, or
17- /// into an owned [ `CString`] .
24+ /// into an owned `CString`.
1825///
19- /// `&CStr` is to [ `CString`] as <code>&[str]</code> is to [ `String`] : the former
26+ /// `&CStr` is to `CString` as <code>&[str]</code> is to `String`: the former
2027/// in each pair are borrowed references; the latter are owned
2128/// strings.
2229///
@@ -25,9 +32,6 @@ use crate::str;
2532/// Instead, safe wrappers of FFI functions may leverage the unsafe [`CStr::from_ptr`] constructor
2633/// to provide a safe interface to other consumers.
2734///
28- /// [`CString`]: ../../std/ffi/struct.CString.html
29- /// [`String`]: ../../std/string/struct.String.html
30- ///
3135/// # Examples
3236///
3337/// Inspecting a foreign C string:
@@ -124,10 +128,13 @@ enum FromBytesWithNulErrorKind {
124128 NotNulTerminated ,
125129}
126130
131+ // FIXME: const stability attributes should not be required here, I think
127132impl FromBytesWithNulError {
133+ #[ rustc_const_stable( feature = "const_cstr_methods" , since = "1.72.0" ) ]
128134 const fn interior_nul ( pos : usize ) -> FromBytesWithNulError {
129135 FromBytesWithNulError { kind : FromBytesWithNulErrorKind :: InteriorNul ( pos) }
130136 }
137+ #[ rustc_const_stable( feature = "const_cstr_methods" , since = "1.72.0" ) ]
131138 const fn not_nul_terminated ( ) -> FromBytesWithNulError {
132139 FromBytesWithNulError { kind : FromBytesWithNulErrorKind :: NotNulTerminated }
133140 }
0 commit comments