1
+ //! [`CStr`] and its related types.
2
+
1
3
use crate :: cmp:: Ordering ;
2
4
use crate :: error:: Error ;
3
5
use crate :: ffi:: c_char;
@@ -9,15 +11,20 @@ use crate::slice;
9
11
use crate :: slice:: memchr;
10
12
use crate :: str;
11
13
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
+
12
19
/// Representation of a borrowed C string.
13
20
///
14
21
/// This type represents a borrowed reference to a nul-terminated
15
22
/// array of bytes. It can be constructed safely from a <code>&[[u8]]</code>
16
23
/// slice, or unsafely from a raw `*const c_char`. It can then be
17
24
/// converted to a Rust <code>&[str]</code> by performing UTF-8 validation, or
18
- /// into an owned [ `CString`] .
25
+ /// into an owned `CString`.
19
26
///
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
21
28
/// in each pair are borrowed references; the latter are owned
22
29
/// strings.
23
30
///
@@ -26,9 +33,6 @@ use crate::str;
26
33
/// Instead, safe wrappers of FFI functions may leverage the unsafe [`CStr::from_ptr`] constructor
27
34
/// to provide a safe interface to other consumers.
28
35
///
29
- /// [`CString`]: ../../std/ffi/struct.CString.html
30
- /// [`String`]: ../../std/string/struct.String.html
31
- ///
32
36
/// # Examples
33
37
///
34
38
/// Inspecting a foreign C string:
@@ -125,10 +129,13 @@ enum FromBytesWithNulErrorKind {
125
129
NotNulTerminated ,
126
130
}
127
131
132
+ // FIXME: const stability attributes should not be required here, I think
128
133
impl FromBytesWithNulError {
134
+ #[ rustc_const_stable( feature = "const_cstr_methods" , since = "1.72.0" ) ]
129
135
const fn interior_nul ( pos : usize ) -> FromBytesWithNulError {
130
136
FromBytesWithNulError { kind : FromBytesWithNulErrorKind :: InteriorNul ( pos) }
131
137
}
138
+ #[ rustc_const_stable( feature = "const_cstr_methods" , since = "1.72.0" ) ]
132
139
const fn not_nul_terminated ( ) -> FromBytesWithNulError {
133
140
FromBytesWithNulError { kind : FromBytesWithNulErrorKind :: NotNulTerminated }
134
141
}
0 commit comments