![crate badge] ![doc badge] ![license badge] ![pre-commit badge] ![coverage doc badge] ![coverage test badge]
WOW! The complete NASA/NAIF Spice toolkit is actually usable on Rust
Intro | Requirements | In action | In development | Usage | Roadmap | Contributors | License
SPICE is An Observation Geometry System for Space Science Missions. Visit their website.
1) Install CSPICE library for your platform.
2) Set the environment variable CSPICE_DIR
to your CSPICE installation folder
(where CSPICE subfolders include
and lib
are located. You can do that in the
Cargo configuration).
3) In the cspice/lib
folder you might need for Unix systems to rename the
static library to match standards: cspice.a
-> libcspice.a
See other requirements at cspice-sys
library which provides
unsafe bindings to CSPICE.
Add the dependency rust-spice to your Cargo.toml
:
toml
[dependencies]
rust-spice = "*" # replace * by the latest version of the crate
A nice and idiomatic interface to Spice,
```rust use spice;
let mut kernel = spice::furnsh("hera/kernels/mk/herastudyPOEMA2024.tm");
let et = spice::str2et("2027-MAR-23 16:00:00"); let (position, light_time) = spice::spkpos("DIMORPHOS", et, "J2000", "NONE", "SUN");
// position -> 18.62640405424448, 21.054373008357004, -7.136291402940499 // light time -> 0.00009674257074746383
spice::unload("hera/kernels/mk/herastudyPOEMA2024.tm"); ```
You can look for some inspirations in the core tests.
Developing an idiomatic interface for Spice in Rust takes time, and not all functions are implemented yet. In the documentation online, a complete guide details which functions are available. If yours is not, you can always use the unsafe API which contains all cspice functions.
For instance, with the unsafe API, the example above would be,
```rust use spice; use std::ffi::CString;
unsafe { let kernel = CString::new("hera/kernels/mk/herastudyPOEMA2024.tm").unwrap().intoraw(); spice::c::furnshc(kernel);
let mut et = 0.0;
let date = CString::new("2027-MAR-23 16:00:00").unwrap().into_raw();
spice::c::str2et_c(date, &mut et);
let target_c = CString::new("DIMORPHOS").unwrap().into_raw();
let frame_c = CString::new("J2000").unwrap().into_raw();
let abcorr_c = CString::new("NONE").unwrap().into_raw();
let observer_c = CString::new("SUN").unwrap().into_raw();
let mut light_time = 0.0;
let mut position = [0.0, 0.0, 0.0];
spice::c::spkpos_c(
target_c,
et,
frame_c,
abcorr_c,
observer_c,
&mut position[0],
&mut light_time,
);
spice::c::unload_c(kernel);
} ```
Much less friendly.. yet it is available. I would love some help in order to complete the idiomatic development. You can raise an issue or propose a pull request for the implementation of a specific function.
Hall of fame:
A huge thanks for their contributions!!
Licensed under the Apache License, Version 2.0.