假设我有一个分配了缓冲区uint8_t*的C++,并且我想从Rust访问它: 一种方法是使用C++函数: uint8_t receive(uint8_t** data, size_t* size) {//allocates the data, writes to it and then points *data to it} 然而,这使得Rustsize_t* size) {
uit8_t* data =
最后,我讨论了这个解决方案,调用C/C++代码为要接收的字符串分配内存,然后释放内存,但它看起来有些难看,必须为未知字符串定义一些特定的长度:pub extern fn rs_string_in_string_outstr_slice.to_owned();
let result = String::from(str_buf + " append from Rustfor output
let c_result = CS
我想将缓冲区从C++发送到Rust,在Rust中读取它们,并在不再需要它们的时候在C++上销毁它们。例如,我可能会使用一个字符串: std::string* s = new std::string("hello"); 然后简单地将s.c_str()作为uint8_t*传递给Rust。我不能简单地调用delete[] s.c_str(),我需要删除C++端的s字符串。因此,我正在考虑向我的函数smol_stack_smol_socke