diff options
Diffstat (limited to 'lib.rs-part0')
-rw-r--r-- | lib.rs-part0 | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib.rs-part0 b/lib.rs-part0 new file mode 100644 index 0000000..d2578cd --- /dev/null +++ b/lib.rs-part0 @@ -0,0 +1,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() +} |