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" )] |
78 | extern crate alloc; |
79 | |
80 | #[cfg (feature = "std" )] |
81 | extern crate std; |
82 | |
83 | mod date; |
84 | mod duration; |
85 | pub mod error; |
86 | pub mod ext; |
87 | #[cfg (any(feature = "formatting" , feature = "parsing" ))] |
88 | pub mod format_description; |
89 | #[cfg (feature = "formatting" )] |
90 | pub mod formatting; |
91 | #[cfg (feature = "std" )] |
92 | mod instant; |
93 | mod internal_macros; |
94 | #[cfg (feature = "macros" )] |
95 | pub mod macros; |
96 | mod month; |
97 | mod offset_date_time; |
98 | #[cfg (feature = "parsing" )] |
99 | pub mod parsing; |
100 | mod primitive_date_time; |
101 | #[cfg (feature = "quickcheck" )] |
102 | mod quickcheck; |
103 | #[cfg (feature = "rand" )] |
104 | mod rand; |
105 | #[cfg (feature = "serde" )] |
106 | #[allow (missing_copy_implementations, missing_debug_implementations)] |
107 | pub mod serde; |
108 | mod sys; |
109 | #[cfg (test)] |
110 | mod tests; |
111 | mod time; |
112 | mod utc_offset; |
113 | pub mod util; |
114 | mod weekday; |
115 | |
116 | pub use time_core::convert; |
117 | |
118 | pub use crate::date::Date; |
119 | pub use crate::duration::Duration; |
120 | pub use crate::error::Error; |
121 | #[doc (hidden)] |
122 | #[cfg (feature = "std" )] |
123 | #[allow (deprecated)] |
124 | pub use crate::instant::Instant; |
125 | pub use crate::month::Month; |
126 | pub use crate::offset_date_time::OffsetDateTime; |
127 | pub use crate::primitive_date_time::PrimitiveDateTime; |
128 | pub use crate::time::Time; |
129 | pub use crate::utc_offset::UtcOffset; |
130 | pub use crate::weekday::Weekday; |
131 | |
132 | /// An alias for [`std::result::Result`] with a generic error from the time crate. |
133 | pub type Result<T> = core::result::Result<T, Error>; |
134 | |
135 | /// This is a separate function to reduce the code size of `expect_opt!`. |
136 | #[inline (never)] |
137 | #[cold ] |
138 | #[track_caller ] |
139 | const fn expect_failed(message: &str) -> ! { |
140 | panic!("{}" , message) |
141 | } |
142 | |