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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
/*! # **rust-spice** WOW! The complete NASA/NAIF Spice toolkit is actually usable on Rust. ## Using **rust-spice** Simply add the following to your `Cargo.toml` file: ```.ignore [dependencies] rust-spice = "*" // replace * by the latest version of the crate ``` Rust layered Spice functions of **rust-spice** are grouped in the root module `spice::` and all wrapper functions in `spice::c::`. You can find a guide for the Rust interface [here][crate::core]. ## **rust-spice** basics ```.ignore use spice; // ugly: using binded C Spice. unsafe { let kernel = CString::new("/path/to/metakernel.mk").unwrap().into_raw(); spice::c::furnsh_c(kernel); spice::c::unload_c(kernel); } // pretty: using the nice Rust interface. let mut kernel = spice::Kernel::new("/path/to/metakernels.mk")?; kernel.unload()?; ``` ## In action With this code, you can get the evolution of the distance in the system. ```.ignore use itertools::multizip; use spice; // Define the system. let mut system = spice::SystemBuilder::default() .kernel("/path/to/metakernels.mk")? .frame("J2000") .observer("HERA") .target("DIMORPHOS") .start_date("2027-MAR-23 16:00:00") .duration(129.0 * spice::DAY) .aberration_correction("NONE") .build()?; // Define the time step. let time_step = 1.0 * spice::DAY; // Get all the times string-formatted. let times = system.times_formatted(time_step); // Get all the positions at the times. let positions = system.positions(time_step); // Get the distances from the positions. let distances = spice::distance(positions); // Display for (time, distance) in multizip((times.iter(), distances.iter())) { println!("{} -> {:.2} km", time, distance); } // Always unload the kernels. system.unload()?; ``` You can also read other [examples](https://github.com/GregoireHENRY/rust-spice/tree/main/examples). ## Rust layer in development The Rust layer is nicer to use: no unsafe and easy types. But it takes a long time to write because it is not automated, I have to do it by hand. I started from my needs, basically getting positions from start to end date of target in referential. I will implemented a nice Rust layer more and more when I will need to use other functions. You can submit issues if you want a layer to some functionalities, and we will implement it immediately. Pull requests are also welcomed to help! The Rust layer for the most Used C Spice API for accessing kernel data is located in [`core`]. The type [`System`] provides some tools, built on top of spice. */ extern crate cspice_sys; extern crate itertools; extern crate nalgebra as na; extern crate serial_test; extern crate tool; /// Complete NASA/NAIF C Spice binded functions, very unsafe, from [`cspice_sys`] wrapper. pub mod c { pub use cspice_sys::*; } /// The Rust layer to ease the use of the wrapper. pub mod core; /// Tools developped on top of Spice for even easier usage of the library. pub mod spicetools; pub use crate::core::*; pub use crate::spicetools::*;