MCPcopy Create free account
hub / github.com/TanTanDev/runity / string_to_cstring_ptr

Function string_to_cstring_ptr

rust/shared/src/utils.rs:6–17  ·  view source on GitHub ↗

only use for passing to other language

(string: &str)

Source from the content-addressed store, hash-verified

4
5// only use for passing to other language
6pub fn string_to_cstring_ptr(string: &str) -> Result<*const c_char, ()> {
7 let name_cstr = match CString::new(string) {
8 Ok(name_cstr) => name_cstr,
9 Err(err) => {
10 error!("failed to turn {} into cstring err {:?}", string, err);
11 return Err(());
12 },
13 };
14 let name_ptr = name_cstr.as_ptr();
15 std::mem::forget(name_cstr);
16 Ok(name_ptr)
17}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected