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/// Turns a list of string literals into an array of `&'static [u8]`.
60macro_rules! byte_arrays {
61    ( $( $s:literal ),+ $(,)? ) => {
62        [ $( $s.as_bytes() ),+ ]
63    };
64}
65
66// _________________________________________
67// FEATURE MOD
68// _________________________________________
69#[cfg(feature = "parse")]
70mod alloc_parse;
71
72#[cfg(feature = "wire")]
73mod wire;
74
75// _________________________________________
76// MOD
77// _________________________________________
78mod an_err;
79mod drift;
80mod dt;
81mod light_time;
82mod lite_str;
83mod locale;
84mod position;
85mod scale;
86mod strptime;
87mod time_parts;
88mod time_range;
89mod ymdhms;
90
91// _________________________________________
92// PUB MOD
93// _________________________________________
94pub mod constants;
95pub mod error;
96pub mod historical_utc;
97pub mod leap_seconds;
98pub mod math;
99pub mod tz;
100
101// _________________________________________
102// FEATURE PUB MOD
103// _________________________________________
104#[cfg(feature = "eop")]
105pub mod eop;
106
107#[cfg(feature = "sidereal")]
108pub mod sidereal;
109
110// _________________________________________
111// FEATURE CRATE USE
112// _________________________________________
113#[cfg(feature = "parse")]
114pub(crate) use alloc_parse::{
115    alloc_constants::*, date::*, date_classification::*, duration::*, parse_date::*, types::*,
116};
117#[cfg(feature = "parse")]
118pub(crate) use locale::{lang_data::*, lang_map::*};
119
120// _________________________________________
121// CRATE USE
122// _________________________________________
123pub(crate) use constants::*;
124pub(crate) use locale::*;
125#[allow(unused_imports)]
126pub(crate) use math::{
127    atan2::atan2,
128    cos::cos,
129    div::rem_euclid_f,
130    floor::floor_f,
131    log::log,
132    sin::sin,
133    sqrt::{hypot, sqrt},
134};
135pub(crate) use strptime::*;
136
137// _________________________________________
138// FEATURE PUB USE
139// _________________________________________
140#[cfg(feature = "parse")]
141pub use alloc_parse::types::{Mode, Order, ParseCfg};
142
143#[cfg(feature = "wire")]
144pub use an_err::{WireErr, WireLocation};
145
146#[cfg(feature = "sidereal")]
147pub use sidereal::Sidereal;
148
149#[cfg(feature = "mars")]
150pub use dt::mars;
151
152// _________________________________________
153// PUB USE
154// _________________________________________
155pub use an_err::AnErr;
156pub use drift::{Drift, Spacetime};
157pub use dt::numbers_traits::{AttosTraits, TimeTraits};
158pub use dt::{Dt, lunar};
159pub use error::{DtErr, DtErrKind};
160pub use light_time::ObserverState;
161pub use lite_str::{LiteStr, LiteStrErr};
162pub use locale::Lang;
163pub use position::{Position, Velocity};
164pub use scale::Scale;
165pub use strptime::StrPTimeFmt;
166pub use time_parts::{Meridiem, Offset, TimeParts, Weekday};
167pub use time_range::{Every, TimeRange};
168pub use ymdhms::YmdHms;