-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
26 lines (20 loc) · 768 Bytes
/
Copy pathlib.rs
File metadata and controls
26 lines (20 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
extern crate similar;
use similar::TextDiff;
use std::ffi::{CStr, CString};
#[no_mangle]
pub extern "C" fn hello(name: *const libc::c_char) {
let name_cstr = unsafe { CStr::from_ptr(name) };
let name = name_cstr.to_str().unwrap();
println!("Hello {}!", name);
}
#[no_mangle]
pub extern "C" fn diff(prev: *const libc::c_char, newtt: *const libc::c_char) -> *mut libc::c_char {
let message_cstr = unsafe { CStr::from_ptr(prev) };
let message = message_cstr.to_str().unwrap();
let new_message_cstr = unsafe { CStr::from_ptr(newtt) };
let new_message = new_message_cstr.to_str().unwrap();
let diff = TextDiff::from_lines(message, new_message);
CString::new(diff.unified_diff().to_string())
.unwrap()
.into_raw()
}