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
//! A Rust crate that provides safe Rust bindings to the Essential Routines for Fundamental Astronomy ([ERFA](https://github.com/liberfa/erfa))
//! C library, which is based on the Standards of Fundamental Astronomy ([SOFA](https://www.iausofa.org/index.html)) library published by
//! the International Astronomical Union (IAU).
//!
//! ## Usage
//! With this crate, functions in ERFA can be called safely in Rust:
//! ```rust
//! use erfars::calendar::Cal2jd;
//!
//! fn main() {
//! let ((jd0, jd1), _) = Cal2jd(2025, 1, 22).unwrap();
//! assert_eq!(jd0+jd1, 2460697.5)
//! }
//! ```
//!
//! ### A note on array arguments in functions
//! Many of the ERFA C functions pass data in the form of multidimensional arrays. For example, a `double[3][3]`
//! represents a 3x3 matrix of double-precision floating-point values. However, Rust does not have
//! an equivalent and clean way of representing this in code. A `double[3][3]` is stored in row-major order,
//! so the Rust equivalent in memory is simply an array `[f64; 9]`. More specifically, the following
//! variable declarations are equivalent:
//!
//! In C:
//! ```c
//! double xyz[3][3] = { {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0} };
//! ```
//!
//! In Rust:
//! ```rust
//! let xyz: [f64; 9] = [0.0; 9];
//! ```
//!
//! Where the first three elements of the Rust array are the first row of the C array, and the second group
//! of three elements in the Rust array are the second row of the C array, and so on.
//!
//! For the user, this means that wherever you see something like a `double[2][3]` or a `double[3][3]` in
//! the ERFA C API, you can safely pass a `[f64; 6]` or a `[f64; 9]` Rust value.
//!
//! ### A note on return values for some ERFA functions
//! Some of the safe Rust ERFA functions return a [`ERFAResult`], which encapsulates both warnings and errors returned from ERFA.
//! The [`Ok`] value of this result contains both the actual
//! result and the warning code as a tuple. The warning code is equal to zero if all is ok.
//! Warning codes from ERFA are always greater than zero, which means you can handle errors using something like:
//!
//! ```rust
//! use erfars::calendar::Jdcalf;
//!
//! fn main() {
//! // Panics on error
//! // If a warning is raised, `warn` is > 0
//! let (res, warn) = Jdcalf(2460697.0, 0.5, 2).unwrap();
//! if warn > 0 {
//! // Do something
//! }
//! }
//! ```
//!
//! The meaning of the warning/error codes can be found in the ERFA docs for the relevant function.
// Stop the linter from complaining about the ERFA function names
pub use ;
/// A return type for ERFA functions which contains both a warning code and an error code.
pub type ERFAResult<T> = ;
pub use unexpected_val_err;