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