spice/core/neat.rs
1/*!
2Improvement on the procedurally generated functions.
3
4## Description
5
6The idiomatic Rust bindings to CSPICE can be very hard to generate in a procedural macro in some
7specific cases. You can find, in this module, functions wrapped from [`raw`] to better match
8an idiomatic usage. The improvements consists in functions:
9
10+ taking a string as input in C requires to also send the size of the pointer to a char array. In Rust, you
11 only send the string.
12+ taking taking input for array size and outputing size whereas a vector can be used
13+ which outputs string that be allocated from default length sometimes
14*/
15
16use crate::raw;
17use crate::MAX_LEN_OUT;
18#[cfg(any(feature = "lock", doc))]
19use {crate::SpiceLock, spice_derive::impl_for};
20
21/**
22Translate the SPICE integer code of a body into a common name for that body.
23
24See [`raw::bodc2n`] for the raw interface.
25*/
26#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
27pub fn bodc2n(code: i32) -> (String, bool) {
28 raw::bodc2n(code, MAX_LEN_OUT as i32)
29}
30
31/**
32This routine converts an input epoch represented in TDB seconds past the TDB epoch of J2000 to a
33character string formatted to the specifications of a user's format picture.
34
35See [`raw::timout`] for the raw interface.
36*/
37#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
38pub fn timout(et: f64, pictur: &str) -> String {
39 raw::timout(et, pictur, pictur.len())
40}
41
42/**
43Fetch triangular plates from a type 2 DSK segment.
44
45See [`raw::dskp02`] for the raw interface.
46*/
47#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
48pub fn dskp02(handle: i32, dladsc: raw::DLADSC) -> Vec<[i32; 3]> {
49 let (_nv, np) = raw::dskz02(handle, dladsc);
50 raw::dskp02(handle, dladsc, 1, np as _)
51}
52
53/**
54Fetch vertices from a type 2 DSK segment.
55
56See [`raw::dskv02`] for the raw interface.
57*/
58#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
59pub fn dskv02(handle: i32, dladsc: raw::DLADSC) -> Vec<[f64; 3]> {
60 let (nv, _np) = raw::dskz02(handle, dladsc);
61 raw::dskv02(handle, dladsc, 1, nv as _)
62}
63
64/**
65Fetch vertices from a type 2 DSK segment.
66
67See [`raw::kdata`] for the raw interface.
68*/
69#[cfg_attr(any(feature = "lock", doc), impl_for(SpiceLock))]
70pub fn kdata(which: i32, kind: &str) -> (String, String, String, i32, bool) {
71 raw::kdata(
72 which,
73 kind,
74 MAX_LEN_OUT as i32,
75 MAX_LEN_OUT as i32,
76 MAX_LEN_OUT as i32,
77 )
78}