1extern crate libc;
5extern "C" {
8 fn version() -> libc::c_float;
9 fn clean();
10 fn update();
11 fn init();
13 fn get(p_name: *const libc::c_uchar, out_path: *const libc::c_uchar);
14 fn uninstall(p_name: *const libc::c_uchar);
15 fn installSpmFile(pkg_name: *const libc::c_uchar, as_dep: i32);
16 fn sync();
17}
18
19const VERSION: &str = "0.04";
22
23
24pub fn init_spm() {
26 unsafe {
27 init();
28 }
29}
30pub fn sync_db() {
32 unsafe {
33 sync();
34 }
35}
36
37pub fn install_spm_file(pkg_name: String, as_dep: i32) {
38 unsafe {
39 installSpmFile(pkg_name.as_ptr(), as_dep);
40 }
41}
42
43pub fn get_version() -> f32 {
45 unsafe { crate::version() }
46}
47pub fn clean_dirs() {
49 unsafe {
50 crate::clean();
51 }
52}
53pub fn get_package(package_name: String, out_path: String) {
55 unsafe {
56 get(package_name.as_ptr(), out_path.as_ptr());
57 }
58}
59
60pub fn uninstall_package(package_name: String) {
62 unsafe {
63 uninstall(package_name.as_ptr());
64 }
65}
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn version_test() {
73 println!(
74 "LibSPM version: {}\nLibSPM-rs wrapper version: {}",
75 get_version(),
76 VERSION
77 );
78 }
79
80 #[test]
81 fn test_clean() {
82 clean_dirs()
83 }
84
85 }