1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//! Uptime formatting
//!
//! "Uptime"-style strings, e.g:
//! ```rust
//! # use readable::up::*;
//! const SECONDS: usize = 158079;
//!
//! assert_eq!(Uptime::from(SECONDS), "1d, 19h, 54m, 39s");
//! assert_eq!(UptimeFull::from(SECONDS), "1 day, 19 hours, 54 minutes, 39 seconds");
//! assert_eq!(Htop::from(SECONDS), "1 day, 19:54:39");
//! ```
//!
//! ## Input
//! **The input is always assumed to be in seconds.**
//!
//! [`From`] input can be:
//! - Any unsigned integer [`u8`], [`usize`], etc
//! - Any signed integer [`i8`], [`isize`], etc
//! - [`f32`] or [`f64`]
//! - [`std::time::Duration`]
//! - [`std::time::Instant`]
//! - Other [`Uptime`] types
//!
//! ## Errors
//! The max input is [`u32::MAX`] seconds.
//!
//! A [`Uptime::UNKNOWN`] (or a variant's version of it) will be returned if the input is:
//! - A negative integer
//! - Larger than [`Uptime::MAX`]
//! - [`f32::NAN`], [`f32::INFINITY`], [`f32::NEG_INFINITY`] (or the [`f64`] versions)
//!
//! ## Uptime
//! This module contains [`Uptime`] which is a trait that allows direct conversion
//! from the _live_ system uptime to a type within this module, e.g:
//!
//! ```rust
//! # use readable::up::*;
//! // Introduce trait into scope.
//! use readable::up::Uptime;
//!
//! // Capture the _current_ system uptime,
//! // and format it into a `Uptime`.
//! let uptime: Uptime = Uptime::sys_uptime();
//! std::thread::sleep(std::time::Duration::from_secs(1));
//! # // Get around CI.
//! # let uptime = 1;
//! assert!(uptime >= 1);
//! ```
//!
//! Only the types within `readable::up` implement this trait.
//!
//! ## From other [`Uptime`] types
//! All types in this module support lossless conversion with each other using [`From`].
//!
//! If the type is an `unknown` variant, that will also be maintained.
//!
//! ```rust
//! # use readable::up::*;
//! // Uptime
//! let uptime = Uptime::from(86461);
//! assert_eq!(uptime, "1d, 1m, 1s");
//!
//! // UptimeFull
//! let uptime_full = UptimeFull::from(uptime);
//! assert_eq!(uptime_full, "1 day, 1 minute, 1 second");
//!
//! // Htop
//! let htop = Htop::from(uptime_full);
//! assert_eq!(htop, "1 day, 00:01:01");
//!
//! // ... wrapping full circle.
//! let uptime2 = Uptime::from(htop);
//! assert_eq!(uptime, uptime2);
//!
//! // Maintain the `unknown` variant.
//! let unknown = Uptime::UNKNOWN;
//! assert_eq!(unknown, Uptime::UNKNOWN);
//! assert_eq!(Htop::from(unknown), Htop::UNKNOWN);
//! ```
//!
//! ## Naive Uptime
//! These types naively assume that:
//! 1. Each day is `86400` seconds
//! 2. Each month is `31` days
//! 3. Each year is `365` days
//!
//! This is incorrect as not all months are 31 days long and leap years exist.
//!
//! ## Formatting
//! The formatting for [`Uptime`] & [`UptimeFull`] is:
//! - The lowest unit is `second`
//! - The highest is `year`
//! - `week` is skipped in favor of `7 days`
//!
//! See [`Htop`] for its formatting rules.
//!
//! ## Copy
//! [`Copy`] is available.
//!
//! The actual strings used internally are not [`String`](https://doc.rust-lang.org/std/string/struct.String.html)'s,
//! but byte array buffer(s). See the specific type for more details.
//!
//! The documentation will still refer to the inner buffer as a [`String`]. Anything returned will also be a [`String`].
//!
//! ```
//! # use readable::up::*;
//! let a = Uptime::from(100_000);
//!
//! // Copy 'a', use 'b'.
//! let b = a;
//! assert_eq!(b, 100_000);
//!
//! // We can still use 'a'
//! assert_eq!(a, 100_000);
//! ```
//!
//! ## Math
//! These operators are overloaded. They will always output a new [`Self`]:
//! - `Add +`
//! - `Sub -`
//! - `Div /`
//! - `Mul *`
//! - `Rem %`
//!
//! They can either be:
//! - Combined with another [`Self`]: `Uptime::from(1) + Uptime::from(1)`
//! - Or with the inner number itself: `Uptime::from(1) + 1`
//!
//! ```rust
//! # use readable::up::*;
//! assert!(Uptime::from(10_u32) + 10 == Uptime::from(20_u32));
//! assert!(Uptime::from(10_u32) - 10 == Uptime::from(0_u32));
//! assert!(Uptime::from(10_u32) / 10 == Uptime::from(1_u32));
//! assert!(Uptime::from(10_u32) * 10 == Uptime::from(100_u32));
//! assert!(Uptime::from(10_u32) % 10 == Uptime::from(0_u32));
//! ```
pub use *;
pub use *;
pub use *;
pub use *;