summaryrefslogtreecommitdiff
path: root/lib.rs-part0
blob: d2578cd25a8058b706615515178c130cfb2bf58d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
use std::os::raw::{c_char};
use std::ffi::{CString, CStr};

#[no_mangle]
pub extern fn rust_func(to: *const c_char) -> *mut c_char {
    let c_str = unsafe { CStr::from_ptr(to) };
    let recipient = match c_str.to_str() {
        Err(_) => "there",
        Ok(string) => string,
    };

    CString::new("Hello ".to_owned() + recipient).unwrap().into_raw()
}