Skip to main content

deep_time/
lib.rs

1#![cfg_attr(test, allow(clippy::all))]
2#![cfg_attr(not(feature = "std"), no_std)]
3
4#[cfg(feature = "alloc")]
5extern crate alloc;
6#[cfg(feature = "std")]
7extern crate std;
8
9// ──────────────────────────────────────────────────────────────
10// Optional panic handler (opt-in via feature)
11// ──────────────────────────────────────────────────────────────
12#[cfg(all(feature = "panic-handler", not(feature = "std"), not(test)))]
13use core::panic::PanicInfo;
14
15#[cfg(all(feature = "panic-handler", not(feature = "std"), not(test)))]
16#[panic_handler]
17fn panic(_info: &PanicInfo) -> ! {
18    // Uses spin_loop() for better power characteristics than plain loop{}
19    loop {
20        core::hint::spin_loop();
21    }
22}
23
24/// Alias for f64, maybe upgrade one day
25pub type Real = f64;
26
27/// Convert a number to the crates [`Real`] type (f64).
28///
29/// Equivalent to `n as f64`.
30#[macro_export]
31macro_rules! f {
32    ($x:expr) => {
33        $x as $crate::Real
34    };
35}
36
37/// Safe Euclidean division.
38/// Returns `default` if `rhs == 0` or if `lhs == i128::MIN && rhs == -1`.
39macro_rules! safe_div_euc {
40    ($lhs:expr, $rhs:expr, $default:expr) => {{
41        match ($lhs).checked_div_euclid($rhs) {
42            Some(q) => q,
43            None => $default,
44        }
45    }};
46}
47
48/// Safe Euclidean remainder.
49/// Returns `$default` if `rhs == 0` or if `lhs == Self::MIN && rhs == -1`.
50macro_rules! safe_rem_euc {
51    ($lhs:expr, $rhs:expr, $default:expr) => {{
52        match ($lhs).checked_rem_euclid($rhs) {
53            Some(r) => r,
54            None => $default,
55        }
56    }};
57}
58
59// _________________________________________
60// FEATURE MOD
61// _________________________________________
62#[cfg(feature = "parse")]
63mod alloc_parse;
64
65#[cfg(feature = "wire")]
66mod wire;
67
68// _________________________________________
69// MOD
70// _________________________________________
71mod an_err;
72mod drift;
73mod dt;
74mod light_time;
75mod lite_str;
76mod position;
77mod scale;
78mod strptime;
79mod time_parts;
80mod time_range;
81mod ymdhms;
82
83// _________________________________________
84// PUB MOD
85// _________________________________________
86pub mod constants;
87pub mod error;
88pub mod historical_sofa;
89pub mod leap_seconds;
90pub mod math;
91pub mod tzdb;
92
93// _________________________________________
94// FEATURE PUB MOD
95// _________________________________________
96#[cfg(feature = "eop")]
97pub mod eop;
98
99#[cfg(feature = "sidereal")]
100pub mod sidereal;
101
102// _________________________________________
103// FEATURE CRATE USE
104// _________________________________________
105#[cfg(feature = "parse")]
106pub(crate) use alloc_parse::{
107    alloc_constants::*, date::*, date_classification::*, duration::*, lang_data::*, lang_map::*,
108    languages::en::*, parse_date::*, types::*,
109};
110
111// _________________________________________
112// CRATE USE
113// _________________________________________
114pub(crate) use constants::*;
115#[allow(unused_imports)]
116pub(crate) use math::{
117    atan2::atan2,
118    cos::cos,
119    div::rem_euclid_f,
120    floor::floor_f,
121    log::log,
122    sin::sin,
123    sqrt::{hypot, sqrt},
124};
125pub(crate) use strptime::*;
126
127// _________________________________________
128// FEATURE PUB USE
129// _________________________________________
130#[cfg(feature = "parse")]
131pub use alloc_parse::types::{Lang, Mode, Order, ParseCfg};
132
133#[cfg(feature = "wire")]
134pub use an_err::{WireErr, WireLocation};
135
136#[cfg(feature = "sidereal")]
137pub use sidereal::Sidereal;
138
139#[cfg(feature = "mars")]
140pub use dt::mars;
141
142// _________________________________________
143// PUB USE
144// _________________________________________
145pub use an_err::AnErr;
146pub use drift::{Drift, Spacetime};
147pub use dt::numbers_traits::{AttosTraits, TimeTraits};
148pub use dt::{Dt, lunar};
149pub use error::{DtErr, DtErrKind};
150pub use light_time::ObserverState;
151pub use lite_str::{LiteStr, LiteStrErr};
152pub use position::{Position, Velocity};
153pub use scale::Scale;
154pub use strptime::StrPTimeFmt;
155pub use time_parts::{Meridiem, Offset, TimeParts, Weekday};
156pub use time_range::{Every, TimeRange};
157pub use ymdhms::{YmdHms, YmdHmsRich};