我正在尝试获取C库返回的C字符串,并通过FFI将其转换为Rust字符串.
mylib.c
const char* hello(){
return "Hello World!";
}
Run Code Online (Sandbox Code Playgroud)
main.rs
#![feature(link_args)]
extern crate libc;
use libc::c_char;
#[link_args = "-L . -I . -lmylib"]
extern {
fn hello() -> *c_char;
}
fn main() {
//how do I get a str representation of hello() here?
}
Run Code Online (Sandbox Code Playgroud)