time/
lib.rs

1//! # Feature flags
2//!
3//! This crate exposes a number of features. These can be enabled or disabled as shown
4//! [in Cargo's documentation](https://doc.rust-lang.org/cargo/reference/features.html). Features
5//! are _disabled_ by default unless otherwise noted.
6//!
7//! Reliance on a given feature is always indicated alongside the item definition.
8//!
9//! - `std` (_enabled by default, implicitly enables `alloc`_)
10//!
11//!   This enables a number of features that depend on the standard library.
12//!
13//! - `alloc` (_enabled by default via `std`_)
14//!
15//!   Enables a number of features that require the ability to dynamically allocate memory.
16//!
17//! - `macros`
18//!
19//!   Enables macros that provide compile-time verification of values and intuitive syntax.
20//!
21//! - `formatting` (_implicitly enables `std`_)
22//!
23//!   Enables formatting of most structs.
24//!
25//! - `parsing`
26//!
27//!   Enables parsing of most structs.
28//!
29//! - `local-offset` (_implicitly enables `std`_)
30//!
31//!   This feature enables a number of methods that allow obtaining the system's UTC offset.
32//!
33//! - `large-dates`
34//!
35//!   By default, only years within the ±9999 range (inclusive) are supported. If you need support
36//!   for years outside this range, consider enabling this feature; the supported range will be
37//!   increased to ±999,999.
38//!
39//!   Note that enabling this feature has some costs, as it means forgoing some optimizations.
40//!   Ambiguities may be introduced when parsing that would not otherwise exist.
41//!
42//! - `serde`
43//!
44//!   Enables [serde](https://docs.rs/serde) support for all types.
45//!
46//! - `serde-human-readable` (_implicitly enables `serde`, `formatting`, and `parsing`_)
47//!
48//!   Allows serde representations to use a human-readable format. This is determined by the
49//!   serializer, not the user. If this feature is not enabled or if the serializer requests a
50//!   non-human-readable format, a format optimized for binary representation will be used.
51//!
52//!   Libraries should never enable this feature, as the decision of what format to use should be up
53//!   to the user.
54//!
55//! - `rand`
56//!
57//!   Enables [rand](https://docs.rs/rand) support for all types.
58//!
59//! - `quickcheck` (_implicitly enables `alloc`_)
60//!
61//!   Enables [quickcheck](https://docs.rs/quickcheck) support for all types.
62//!
63//! - `wasm-bindgen`
64//!
65//!   Enables [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) support for converting
66//!   [JavaScript dates](https://rustwasm.github.io/wasm-bindgen/api/js_sys/struct.Date.html), as
67//!   well as obtaining the UTC offset from JavaScript.
68
69#![doc(html_playground_url = "https://play.rust-lang.org")]
70#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_notable_trait))]
71#![no_std]
72#![doc(html_favicon_url = "https://avatars0.githubusercontent.com/u/55999857")]
73#![doc(html_logo_url = "https://avatars0.githubusercontent.com/u/55999857")]
74#![doc(test(attr(deny(warnings))))]
75
76#[allow(unused_extern_crates)]
77#[cfg(feature = "alloc")]
78extern crate alloc;
79
80#[cfg(feature = "std")]
81extern crate std;
82
83mod date;
84mod duration;
85pub mod error;
86pub mod ext;
87#[cfg(any(feature = "formatting", feature = "parsing"))]
88pub mod format_description;
89#[cfg(feature = "formatting")]
90pub mod formatting;
91mod hint;
92#[cfg(feature = "std")]
93mod instant;
94mod internal_macros;
95#[cfg(feature = "macros")]
96pub mod macros;
97mod month;
98mod offset_date_time;
99#[cfg(feature = "parsing")]
100pub mod parsing;
101mod primitive_date_time;
102#[cfg(feature = "quickcheck")]
103mod quickcheck;
104#[cfg(feature = "rand")]
105mod rand;
106#[cfg(feature = "serde")]
107pub mod serde;
108mod sys;
109#[cfg(test)]
110mod tests;
111mod time;
112mod utc_date_time;
113mod utc_offset;
114pub mod util;
115mod weekday;
116
117pub use time_core::convert;
118
119pub use crate::date::Date;
120pub use crate::duration::Duration;
121pub use crate::error::Error;
122#[doc(hidden)]
123#[cfg(feature = "std")]
124#[allow(deprecated)]
125pub use crate::instant::Instant;
126pub use crate::month::Month;
127pub use crate::offset_date_time::OffsetDateTime;
128pub use crate::primitive_date_time::PrimitiveDateTime;
129pub use crate::time::Time;
130pub use crate::utc_date_time::UtcDateTime;
131pub use crate::utc_offset::UtcOffset;
132pub use crate::weekday::Weekday;
133
134/// An alias for [`std::result::Result`] with a generic error from the time crate.
135pub type Result<T> = core::result::Result<T, Error>;
136
137/// This is a separate function to reduce the code size of `expect_opt!`.
138#[inline(never)]
139#[cold]
140#[track_caller]
141const fn expect_failed(message: &str) -> ! {
142    panic!("{}", message)
143}