#[unsafe(no_mangle)]pub unsafe extern "C" fn nstd_cstring_from_cstr<'a>(
allocator: &'a NSTDAllocator,
cstr: &NSTDCStr,
) -> NSTDOptionalCString<'a>Available on crate feature
cstring only.Expand description
Creates an owned version of an unowned C string slice.
§Parameters:
-
const NSTDAllocator *allocator- The memory allocator. -
const NSTDCStr *cstr- The unowned C string slice.
§Returns
NSTDOptionalCString cstring - The new owned version of cstr on success, or an uninitialized
“none” variant if cstr contains a null byte or allocating fails.
§Safety
The caller of this function must ensure that cstr’s data is valid for reads.
§Example
use nstd_sys::{
alloc::NSTD_ALLOCATOR, core::cstr::nstd_core_cstr_from_raw, cstring::nstd_cstring_from_cstr,
};
unsafe {
let cstr = nstd_core_cstr_from_raw("C string\0".as_ptr().cast());
let cstring = nstd_cstring_from_cstr(&NSTD_ALLOCATOR, &cstr);
}