@@ -5,9 +5,8 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
5
5
use flipperzero_sys as sys;
6
6
use ufmt:: derive:: uDebug;
7
7
8
- /// The maximum number of ticks that a [`Duration`] can contain for it to be usable with
9
- /// [`Instant`].
10
- const MAX_DURATION_TICKS : u32 = u32:: MAX / 2 ;
8
+ /// Maximum number of ticks a [`Duration`] can contain to be usable with [`Instant`].
9
+ const MAX_INTERVAL_DURATION_TICKS : u32 = u32:: MAX / 2 ;
11
10
12
11
const NANOS_PER_SEC_F : f64 = 1_000_000_000_f64 ;
13
12
const NANOS_PER_SEC : u64 = 1_000_000_000 ;
@@ -102,7 +101,7 @@ impl Instant {
102
101
/// represented as `Instant` (which means it's inside the bounds of the underlying
103
102
/// data structure), `None` otherwise.
104
103
pub fn checked_add ( & self , duration : Duration ) -> Option < Instant > {
105
- if duration. 0 <= MAX_DURATION_TICKS {
104
+ if duration. 0 <= MAX_INTERVAL_DURATION_TICKS {
106
105
Some ( Instant ( self . 0 . wrapping_add ( duration. 0 ) ) )
107
106
} else {
108
107
None
@@ -113,7 +112,7 @@ impl Instant {
113
112
/// represented as `Instant` (which means it's inside the bounds of the underlying
114
113
/// data structure), `None` otherwise.
115
114
pub fn checked_sub ( & self , duration : Duration ) -> Option < Instant > {
116
- if duration. 0 <= MAX_DURATION_TICKS {
115
+ if duration. 0 <= MAX_INTERVAL_DURATION_TICKS {
117
116
Some ( Instant ( self . 0 . wrapping_sub ( duration. 0 ) ) )
118
117
} else {
119
118
None
@@ -134,10 +133,10 @@ impl Ord for Instant {
134
133
Ordering :: Equal
135
134
} else {
136
135
// We use modular arithmetic to define ordering.
137
- // This requires a maximum `Duration` value of `MAX_DURATION_TICKS `.
136
+ // This requires a maximum `Duration` value of `MAX_INTERVAL_DURATION_TICKS `.
138
137
self . 0
139
138
. wrapping_sub ( other. 0 )
140
- . cmp ( & MAX_DURATION_TICKS )
139
+ . cmp ( & MAX_INTERVAL_DURATION_TICKS )
141
140
. reverse ( )
142
141
}
143
142
}
@@ -195,7 +194,7 @@ impl Sub<Instant> for Instant {
195
194
///
196
195
/// Each `Duration` is composed of a whole number of "ticks", the length of which depends
197
196
/// on the firmware's tick frequency. While a `Duration` can contain any value that
198
- /// is at most [`u32::MAX`] ticks, only the range `[Duration::ZERO..=DURATION::MAX]` can
197
+ /// is at most [`u32::MAX`] ticks, only the range `[Duration::ZERO..=DURATION::MAX/2 ]` can
199
198
/// be used with [`Instant`].
200
199
#[ derive( Clone , Copy , Debug , uDebug, Default , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
201
200
pub struct Duration ( pub ( super ) u32 ) ;
@@ -209,7 +208,7 @@ impl Duration {
209
208
/// May vary by platform as necessary. Must be able to contain the difference between
210
209
/// two instances of [`Instant`]. This constraint gives it a value of about 24 days in
211
210
/// practice on stock firmware.
212
- pub const MAX : Duration = Duration ( MAX_DURATION_TICKS ) ;
211
+ pub const MAX : Duration = Duration ( u32 :: MAX ) ;
213
212
214
213
/// Creates a new `Duration` from the specified number of whole seconds.
215
214
///
@@ -467,7 +466,7 @@ impl<'a> Sum<&'a Duration> for Duration {
467
466
468
467
#[ flipperzero_test:: tests]
469
468
mod tests {
470
- use super :: { ticks_to_ns, Duration , Instant , MAX_DURATION_TICKS } ;
469
+ use super :: { ticks_to_ns, Duration , Instant , MAX_INTERVAL_DURATION_TICKS } ;
471
470
use crate :: println;
472
471
473
472
#[ cfg( feature = "alloc" ) ]
@@ -607,7 +606,8 @@ mod tests {
607
606
start : Option < T > ,
608
607
op : impl Fn ( & T , Duration ) -> Option < T > ,
609
608
) {
610
- const DURATIONS : [ Duration ; 2 ] = [ Duration ( MAX_DURATION_TICKS >> 1 ) , Duration ( 50 ) ] ;
609
+ const DURATIONS : [ Duration ; 2 ] =
610
+ [ Duration ( MAX_INTERVAL_DURATION_TICKS >> 1 ) , Duration ( 50 ) ] ;
611
611
if let Some ( start) = start {
612
612
assert_eq ! (
613
613
op( & start, DURATIONS . into_iter( ) . sum( ) ) ,
0 commit comments