rust-spice 0.4.8

WOW! The complete NASA/NAIF Spice toolkit is actually usable on Rust.
Documentation

rust-spice

logo image

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 | Temporary brief notice | In action | In development | Installation | License


Intro

SPICE is An Observation Geometry System for Space Science Missions. Visit their website.

Temporary brief notice

Apparently the crate is only available for Linux systems. It is due to the fact that the crate is built on top of the wrapper cspice-sys. This problem will be solved in short delays as I plan to remove this dependency and write a build script that uses the cspice library installed on the user's pc.

In action

A nice and idiomatic interface to Spice,

use spice;

let mut kernel = spice::Kernel::new("/path/to/metakernels.mk")?;

let et = spice::str2et("2027-MAR-23 16:00:00");
let (position, light_time) = spice::spkpos(
    "TARGET_NAME", et, "FRAME_NAME", "NONE", "SUN"
);

kernel.unload()?;

Read more in the documentation online and see examples.

In development

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,

use spice;
use std::ffi::CString;

unsafe {
    let kernel = CString::new("/path/to/metakernel.mk").unwrap().into_raw();
    spice::c::furnsh_c(kernel);

    let mut ephemeris_time = 0.0;
    let date = CString::new("2027-MAR-23 16:00:00").unwrap().into_raw();
    spice::c::str2et_c(date, &mut ephemeris_time);

    let target_c = CString::new("TARGET_NAME").unwrap().into_raw();
    let frame_c = CString::new("FRAME_NAME").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,
        ephemeris_time,
        frame_c,
        abcorr_c,
        observer_c,
        &mut position[0],
        &mut light_time,
    );

    spice::c::unload_c(kernel);
}

Much less friendly, but it's 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.

Installation

Add the dependency rust-spice to your Cargo.toml:

...
[dependencies]
rust-spice = "*" # replace * by the latest version of the crate

License

Licensed under the Apache License, Version 2.0.