aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Salzedo <[email protected]>2021-03-21 16:45:48 -0700
committerJoshua Salzedo <[email protected]>2021-03-21 16:45:48 -0700
commitd453b9dd95589d95239ea3f86f15da647d253aef (patch)
tree687937ad1051d6511f337225f3d786fe3d2ce287
parentcf1323fb67b2841a99bb497d7947ffa772ff354d (diff)
Add Struct/impl documentation for embassy::time::Duration
-rw-r--r--embassy/src/time/duration.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/embassy/src/time/duration.rs b/embassy/src/time/duration.rs
index e04afa184..c96007747 100644
--- a/embassy/src/time/duration.rs
+++ b/embassy/src/time/duration.rs
@@ -26,16 +26,18 @@ impl Duration {
26 self.ticks * 1_000_000 / TICKS_PER_SECOND 26 self.ticks * 1_000_000 / TICKS_PER_SECOND
27 } 27 }
28 28
29 /// Creates a duration from the specified number of clock ticks
29 pub const fn from_ticks(ticks: u64) -> Duration { 30 pub const fn from_ticks(ticks: u64) -> Duration {
30 Duration { ticks } 31 Duration { ticks }
31 } 32 }
32 33
34 /// Creates a duration from the specified number of seconds
33 pub const fn from_secs(secs: u64) -> Duration { 35 pub const fn from_secs(secs: u64) -> Duration {
34 Duration { 36 Duration {
35 ticks: secs * TICKS_PER_SECOND, 37 ticks: secs * TICKS_PER_SECOND,
36 } 38 }
37 } 39 }
38 40 /// Creates a duration from the specified number of milliseconds
39 pub const fn from_millis(millis: u64) -> Duration { 41 pub const fn from_millis(millis: u64) -> Duration {
40 Duration { 42 Duration {
41 ticks: millis * TICKS_PER_SECOND / 1000, 43 ticks: millis * TICKS_PER_SECOND / 1000,
@@ -45,30 +47,34 @@ impl Duration {
45 /* 47 /*
46 NOTE: us delays may not be as accurate 48 NOTE: us delays may not be as accurate
47 */ 49 */
50 /// Creates a duration from the specified number of microseconds
51 /// NOTE: Delays this small may be inaccurate.
48 pub const fn from_micros(micros: u64) -> Duration { 52 pub const fn from_micros(micros: u64) -> Duration {
49 Duration { 53 Duration {
50 ticks: micros * TICKS_PER_SECOND / 1_000_000, 54 ticks: micros * TICKS_PER_SECOND / 1_000_000,
51 } 55 }
52 } 56 }
53 57
58 /// Adds one Duration to another, returning a new Duration or None in the event of an overflow.
54 pub fn checked_add(self, rhs: Duration) -> Option<Duration> { 59 pub fn checked_add(self, rhs: Duration) -> Option<Duration> {
55 self.ticks 60 self.ticks
56 .checked_add(rhs.ticks) 61 .checked_add(rhs.ticks)
57 .map(|ticks| Duration { ticks }) 62 .map(|ticks| Duration { ticks })
58 } 63 }
59 64 /// Subtracts one Duration to another, returning a new Duration or None in the event of an overflow.
60 pub fn checked_sub(self, rhs: Duration) -> Option<Duration> { 65 pub fn checked_sub(self, rhs: Duration) -> Option<Duration> {
61 self.ticks 66 self.ticks
62 .checked_sub(rhs.ticks) 67 .checked_sub(rhs.ticks)
63 .map(|ticks| Duration { ticks }) 68 .map(|ticks| Duration { ticks })
64 } 69 }
70 /// Multiplies one Duration to another, returning a new Duration or None in the event of an overflow.
65 71
66 pub fn checked_mul(self, rhs: u32) -> Option<Duration> { 72 pub fn checked_mul(self, rhs: u32) -> Option<Duration> {
67 self.ticks 73 self.ticks
68 .checked_mul(rhs as _) 74 .checked_mul(rhs as _)
69 .map(|ticks| Duration { ticks }) 75 .map(|ticks| Duration { ticks })
70 } 76 }
71 77 /// Divides one Duration against another, returning a new Duration or None in the event of an overflow.
72 pub fn checked_div(self, rhs: u32) -> Option<Duration> { 78 pub fn checked_div(self, rhs: u32) -> Option<Duration> {
73 self.ticks 79 self.ticks
74 .checked_div(rhs as _) 80 .checked_div(rhs as _)