use std::ffi::{CStr, CString};
#[no_mangle]
pub extern "C" fn rust_vec_of_str_new() -> *mut Vec<String> {
return Box::into_raw(Box::new(Vec::<String>::new()));
}
#[no_mangle]
pub extern "C" fn rust_vec_of_str_drop(p: *mut Vec<String>) {
if p.is_null() {
return;
}
unsafe {
let _ = Box::from_raw(p); }
}
#[no_mangle]
pub extern "C" fn rust_vec_of_str_push(instance: *mut Vec<String>, value: *const i8) {
if instance.is_null() {
return;
}
let value = unsafe { CStr::from_ptr(value).to_string_lossy().into_owned() };
let vector = unsafe { &mut *instance };
vector.push(value);
}
#[no_mangle]
pub extern "C" fn rust_vec_of_str_reverse(instance: *mut Vec<String>) {
if instance.is_null() {
return;
}
let vector = unsafe { &mut *instance };
vector.reverse();
}
#[no_mangle]
pub extern "C" fn rust_vec_of_str_join(instance: *mut Vec<String>, sep: *const i8) -> *mut i8 {
if instance.is_null() {
return std::ptr::null_mut();
}
let sep = unsafe { CStr::from_ptr(sep).to_string_lossy().into_owned() };
let vector = unsafe { &mut *instance };
let result = vector.join(&sep);
let c_str = CString::new(result.clone()).unwrap();
let ptr = c_str.into_raw();
return ptr;
}