libswe_sys/swerust/swe02/
handler.rs

1use crate::raw;
2use std::ffi::{CStr, CString};
3use std::os::raw::c_char;
4
5/*
6 * 2. The Ephemeris file related functions
7 */
8
9/// Set the path of ephemeris
10pub fn set_ephe_path(path: &str) {
11    if path.len() > 255 {
12        panic!("swe 2.1 -> set_ephe_path -> path to long");
13    }
14    let c_str = CString::new(path).unwrap();
15    let path_final: *const c_char = c_str.as_ptr() as *const c_char;
16    unsafe {
17        raw::swe_set_ephe_path(path_final);
18    }
19}
20
21/// Close swiss ephemeris, free memory
22pub fn close() {
23    unsafe { raw::swe_close() }
24}
25
26/// Set the path of ephemeris for working with JPL file
27pub fn set_jpl_file(fname: &str) {
28    if fname.len() > 255 {
29        panic!("swe 2.3 -> set_jpl_file -> fname to long");
30    }
31    let c_str = CString::new(fname).unwrap();
32    let fname_final: *const c_char = c_str.as_ptr() as *const c_char;
33    unsafe {
34        raw::swe_set_jpl_file(fname_final);
35    }
36}
37
38/// Get version of swiss ephemeris
39pub fn version() -> String {
40    // Get the version
41    let mut version = [0; 255];
42    let v = unsafe {
43        let p = version.as_mut_ptr();
44        raw::swe_version(p);
45        CStr::from_ptr(p)
46    };
47    CString::from(v).to_str().unwrap().to_string()
48}
49
50/// Get librarx path dll
51pub fn get_library_path() -> String {
52    // Get dll path
53    let mut dll_path = [0; 255];
54    let dll = unsafe {
55        let p = dll_path.as_mut_ptr();
56        raw::swe_get_library_path(p);
57        CStr::from_ptr(p)
58    };
59    CString::from(dll).to_str().unwrap().to_string()
60}