mirror of
https://github.com/guilhermewerner/rust-ffi
synced 2025-06-15 13:24:19 +00:00
15 lines
376 B
Rust
15 lines
376 B
Rust
use libc::c_char;
|
|
use std::ffi::{CStr, CString};
|
|
|
|
/// Convert C string to Rust String.
|
|
pub fn ToString(ptr: *mut c_char) -> String {
|
|
let input = unsafe { CStr::from_ptr(ptr) };
|
|
|
|
return input.to_str().unwrap().to_string();
|
|
}
|
|
|
|
/// Convert Rust String to C string.
|
|
pub fn FromString(string: String) -> *mut c_char {
|
|
return CString::new(string).unwrap().into_raw();
|
|
}
|