Add String Conversion Function

This commit is contained in:
GuilhermeWerner
2021-04-18 20:15:00 -03:00
parent 293aef9dbf
commit d51196ff4b
7 changed files with 75 additions and 0 deletions

14
Source/Converter.rs Normal file
View File

@ -0,0 +1,14 @@
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();
}