hi,
I've seen some examples already but i am quite confused on how to do this. (i've been looking into cxx but i got nothing i understand). I imagine this is not easy to do so if you feel like it is not worth your time, please ignore my post.
what i have is a "simple" situation where i build my cpp code using a builder :
fn main() {
cc::Build::new()
.file("src/test.cpp")
.compile("test");
}
in my main.rs i created a vector of strings that i would like to pass as an input to my function in test.cpp, process it and return another vector of strings back to rust (all will be done in a loop so i imagine freeing memory is required).
main.rs
extern {
fn test_strvec(sv: Vec<String>)->Vec<String>;
}
fn main(){
let v = vec!["aa".to_string(), "bb", "cc"];
let b = unsafe { test_strvec(v) }
println!("{:?}", b);
}
in test.cpp
#include <stdio.h>
#include <string.h>
#include <vector.h>
vector<string> test_strvec(vector<string> sv) {
// print incoming vector
// make a new vector of strings
string a = "aaa";
string b = "bbb";
vector<string> vec;
vec.push_back(a);
vec.push_back(b);
????????????? how to return vec back to rust!!!!!
//
}
let say i want to add 2 new random strings to a new vector and send it back to rust. i apologize for the sparse, incomplete and incorrect example but it just reflects my ignorance on the subject !
Moreover, if passing a string is not smart, 2d vector of char/u8 is also an option, but given i have no clue how to do either i cannot say what to do...
Thank you
A