Created
May 23, 2016 01:22
-
-
Save selfup/4a16eda78d56431005ba2946c31f2b2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#[no_mangle] | |
pub extern fn read_json(ro: *const c_char) -> *const c_char { | |
let roo = make_string(ro); | |
let json_for_rust: HashMap<String, i32> = json::decode(&roo).unwrap(); | |
let encoded = json::encode(&json_for_rust).unwrap(); | |
let concated_string = CString::new(encoded).unwrap(); | |
concated_string.into_raw() | |
} | |
fn make_string(s1: *const c_char) -> String { | |
let s1_cstr = unsafe { CStr::from_ptr(s1) }; | |
let s1_and_str = s1_cstr.to_str().unwrap(); | |
let s1_string = s1_and_str.to_string(); | |
s1_string | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment