Skip to content

Commit 0b3dba9

Browse files
bors[bot]nankeen
andauthored
Merge #364
364: Derive PartialOrd for time module types r=burrbull a=nankeen This PR derives `PartialOrd` for types in the `time` module. Which is useful in cases where it is necessary to compare frequencies. ## Proposed Changes * Derive `PartialOrd` for `Bps` * Derive `PartialOrd` for `Hertz` * Derive `PartialOrd` for `KiloHertz` * Derive `PartialOrd` for `MegaHertz` Co-authored-by: Kai <nankeen@users.noreply.github.com>
2 parents afd8087 + 6f34f7f commit 0b3dba9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3131
- Add GPIOF/GPIOG support for high/xl density lines
3232
- Allow using `Input<PullUp>` and `Input<PullDown>` for all alternate
3333
function inputs.
34+
- Add `PartialOrd` derivation for `Bps`, `Hertz`, `KiloHertz`, and `MegaHertz`
3435

3536
### Fixed
3637

src/time.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use cortex_m::peripheral::{DCB, DWT};
3333
use crate::rcc::Clocks;
3434

3535
/// Bits per second
36-
#[derive(Clone, Copy, PartialEq, Debug)]
36+
#[derive(Clone, Copy, PartialEq, PartialOrd, Debug)]
3737
pub struct Bps(pub u32);
3838

3939
/// Hertz
@@ -52,7 +52,7 @@ pub struct Bps(pub u32);
5252
///
5353
/// let freq = 60.hz();
5454
/// ```
55-
#[derive(Clone, Copy, PartialEq, Debug)]
55+
#[derive(Clone, Copy, PartialEq, PartialOrd, Debug)]
5656
pub struct Hertz(pub u32);
5757

5858
/// Kilohertz
@@ -74,7 +74,7 @@ pub struct Hertz(pub u32);
7474
///
7575
/// let freq = 100.khz();
7676
/// ```
77-
#[derive(Clone, Copy, PartialEq, Debug)]
77+
#[derive(Clone, Copy, PartialEq, PartialOrd, Debug)]
7878
pub struct KiloHertz(pub u32);
7979

8080
/// Megahertz
@@ -95,7 +95,7 @@ pub struct KiloHertz(pub u32);
9595
///
9696
/// let freq = 8.mhz();
9797
/// ```
98-
#[derive(Clone, Copy, PartialEq, Debug)]
98+
#[derive(Clone, Copy, PartialEq, PartialOrd, Debug)]
9999
pub struct MegaHertz(pub u32);
100100

101101
/// Time unit

0 commit comments

Comments
 (0)