Skip to main content

gnss_time/
lib.rs

1//! # gnss-time
2//!
3//! A type-safe GNSS time scale library with zero runtime overhead.
4//!
5//! Supports conversions between:
6//! - GPS
7//! - UTC
8//! - GLONASS
9//! - Galileo
10//! - `BeiDou`
11//! - TAI
12//!
13//! ## Feature flags
14//!
15//! | Feature  | Description                                                          |
16//! |----------|----------------------------------------------------------------------|
17//! | `std`    | `impl std::error::Error` for error types                             |
18//! | `serde`  | `Serialize`/`Deserialize` for `Time<S>`, `Duration`, `DurationParts` |
19//! | `defmt`  | `impl defmt::Format` for all public types                            |
20//!
21//! Leap seconds are handled explicitly via a provider trait, ensuring
22//! deterministic behavior and full `no_std` compatibility.
23//!
24//! ## Design goals
25//!
26//! - Zero allocations
27//! - No global mutable state
28//! - Fully deterministic conversions
29//! - Embedded-friendly (`no_std`)
30//! - Strong type safety across time scales
31//!
32//! ## Quick start
33//!
34//! ```rust
35//! use gnss_time::prelude::*;
36//!
37//! let gps = Time::<Gps>::from_week_tow(
38//!     2345,
39//!     DurationParts {
40//!         seconds: 432_000,
41//!         nanos: 0,
42//!     },
43//! )
44//! .unwrap();
45//!
46//! assert_eq!(gps.to_string(), "GPS 2345:432000.000");
47//!
48//! let utc: Time<Utc> = gps.into_scale_with(LeapSeconds::builtin()).unwrap();
49//!
50//! // ISO 8601 formatting
51//! let dt = utc.to_civil();
52//! println!("{dt}"); // e.g. "2023-01-01T00:00:18.000000000Z"
53//! ```
54
55#![no_std]
56#![forbid(unsafe_code)]
57#![deny(missing_docs)]
58#![deny(clippy::all)]
59#![deny(clippy::pedantic)]
60#![allow(clippy::similar_names)]
61#![warn(clippy::must_use_candidate)]
62#![warn(clippy::missing_const_for_fn)]
63#![warn(clippy::semicolon_if_nothing_returned)]
64
65#[cfg(any(feature = "std", test))]
66extern crate std;
67
68////////////////////////////////////////////////////////////////////////////////
69// Public modules
70////////////////////////////////////////////////////////////////////////////////
71
72// ISO 8601 civil date-time representation derived from `Time<Utc>`.
73pub mod civil;
74
75pub mod convert;
76pub mod duration;
77pub mod epoch;
78pub mod error;
79pub mod leap;
80pub mod matrix;
81pub mod scale;
82pub mod time;
83
84// Serde implementations for `Time<S>`, `Duration`, and `DurationParts`.
85// Enabled by the `serde` feature flag.
86#[cfg(feature = "serde")]
87pub mod serde_impls;
88
89////////////////////////////////////////////////////////////////////////////////
90// Internal modules
91////////////////////////////////////////////////////////////////////////////////
92
93mod tables;
94
95////////////////////////////////////////////////////////////////////////////////
96// Public re-exports
97////////////////////////////////////////////////////////////////////////////////
98
99pub use civil::CivilDateTime;
100pub use convert::*;
101pub use duration::*;
102pub use epoch::*;
103pub use error::*;
104pub use leap::*;
105pub use matrix::*;
106pub use scale::*;
107pub use time::*;
108
109////////////////////////////////////////////////////////////////////////////////
110// Prelude
111////////////////////////////////////////////////////////////////////////////////
112
113// Common imports for typical usage.
114pub mod prelude;