Created
May 18, 2017 17:01
-
-
Save chelseakomlo/e6ec60b0a596c6d924a508d14077d791 to your computer and use it in GitHub Desktop.
CString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate libc; | |
use libc::c_char; | |
use std::ffi::CString; | |
fn get_string() -> String { | |
String::from("hello world!") | |
} | |
#[no_mangle] | |
pub unsafe extern "C" fn c_get_string() -> *mut c_char { | |
let new_str = get_string(); | |
let c_new = CString::new(new_str).unwrap(); | |
c_new.into_raw() | |
} | |
fn main() { | |
println!("{}", get_string()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment