Crate spice[][src]

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:

[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.

rust-spice basics

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.

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.

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.

Re-exports

pub use crate::core::*;
pub use crate::spicetools::*;

Modules

c

Complete NASA/NAIF C Spice binded functions, very unsafe, from cspice_sys wrapper.

core

The Rust layer to ease the use of the wrapper.

spicetools

Tools developped on top of Spice for even easier usage of the library.