Feature gate: #![feature(const_cstr_from_ptr)]
This is a tracking issue for using CStr::from_ptr() in a const context.
This method was previously gated under const_cstr_methods, but was split off after discussion in #107624 (review).
Public API
// core/ffi/c_str.rs
impl CStr {
pub const unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr;
pub const fn count_bytes(&self) -> usize;
}
Steps / History
Unresolved Questions
Making this const currently depends on const_eval_select, which unstable. If const_eval_select becomes internally usable, we will be able to stabilize this.
The other currently available option is to always use a const strlen, but this would come with a performance hit.
Alternatively, whenever CStr becomes a thin pointer this can be const stabilized since it will have no internal operations.
Feature gate:
#![feature(const_cstr_from_ptr)]This is a tracking issue for using
CStr::from_ptr()in a const context.This method was previously gated under
const_cstr_methods, but was split off after discussion in #107624 (review).Public API
Steps / History
Blocked on Relax const-eval restrictions rfcs#3352 (?)Unresolved Questions
Making this const currently depends on
const_eval_select, which unstable. Ifconst_eval_selectbecomes internally usable, we will be able to stabilize this.The other currently available option is to always use a const
strlen, but this would come with a performance hit.Alternatively, whenever
CStrbecomes a thin pointer this can be const stabilized since it will have no internal operations.