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