Skip to content

Commit e418551

Browse files
author
Jason Mobarak
committed
Update to use total_cmp from 1.62
1 parent 4e9e7c6 commit e418551

File tree

4 files changed

+56
-18
lines changed

4 files changed

+56
-18
lines changed

.github/workflows/ci.yaml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
---
12
name: CI
2-
on:
3+
"on":
34
pull_request:
45
push:
56
branches:
@@ -11,15 +12,34 @@ jobs:
1112
strategy:
1213
matrix:
1314
include:
14-
- os: ubuntu-18.04
15+
# Ubuntus
16+
- os: ubuntu-latest
1517
binary_target: x86_64-unknown-linux-musl
1618
needs_musl: true
17-
- os: ubuntu-18.04
19+
toolchain: stable
20+
- os: ubuntu-20.04
1821
binary_target: x86_64-unknown-linux-gnu
19-
- os: macos-10.15
22+
toolchain: stable
23+
24+
# MacOS
25+
- os: macos-11
2026
binary_target: x86_64-apple-darwin
27+
toolchain: stable
28+
29+
# Windows
2130
- os: windows-latest
2231
binary_target: x86_64-pc-windows-msvc
32+
toolchain: stable
33+
34+
# Nightly Rust
35+
- os: ubuntu-latest
36+
binary_target: x86_64-unknown-linux-gnu
37+
toolchain: nightly
38+
39+
# MSRV
40+
- os: ubuntu-latest
41+
binary_target: x86_64-unknown-linux-gnu
42+
toolchain: 1.57.0
2343
steps:
2444
- uses: actions/checkout@v2
2545
with:
@@ -32,7 +52,8 @@ jobs:
3252
sudo apt-get install musl-tools
3353
sudo ln -s /usr/bin/musl-gcc /usr/bin/musl-g++
3454
35-
- name: Install LLVM and Clang # required for bindgen on Windows
55+
# Required for bindgen on Windows
56+
- name: Install LLVM and Clang
3657
uses: KyleMayes/install-llvm-action@v1
3758
if: matrix.os == 'windows-latest'
3859
with:
@@ -49,10 +70,10 @@ jobs:
4970
- name: Install rust ${{ matrix.binary_target }}
5071
uses: actions-rs/toolchain@v1
5172
with:
52-
toolchain: stable-${{ matrix.binary_target }}
73+
toolchain: ${{ matrix.toolchain }}-${{ matrix.binary_target }}
5374
profile: minimal
5475

5576
- uses: actions-rs/cargo@v1
5677
with:
5778
command: make
58-
args: --makefile ci-makefile.toml --no-workspace workspace-ci-flow
79+
args: --no-workspace workspace-ci-flow

ci-makefile.toml renamed to Makefile.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
44
CARGO_MAKE_RUN_CLIPPY = true
55
CARGO_MAKE_CLIPPY_ARGS = "--all-features -- -D warnings"
66
CARGO_MAKE_RUN_CHECK_FORMAT = true
7+
CARGO_MAKE_CARGO_VERBOSE_FLAGS = "-vv"
78
RUSTFLAGS="-D warnings"
89

910
[tasks.check-format-ci-flow]

swiftnav/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ repository = "https://github.com/swift-nav/swiftnav-rs"
99
license = "LGPL-3.0"
1010

1111
[dependencies]
12+
rustversion = "1.0"
1213
chrono = { version = "0.4", optional = true }
1314
swiftnav-sys = { version = "^0.8.0", path = "../swiftnav-sys/" }

swiftnav/src/time.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
//! [`UtcParams`] object to handle the leap second conversion and one which doesn't
4545
//! take a [`UtcParams`] object but has `_hardcoded` appended to the function name.
4646
47-
use std::cmp::Ordering;
4847
use std::error::Error;
4948
use std::fmt;
5049
use std::ops::{Add, AddAssign, Sub, SubAssign};
@@ -301,20 +300,16 @@ impl GpsTime {
301300
GloTime(unsafe { swiftnav_sys::gps2glo(self.c_ptr(), std::ptr::null()) })
302301
}
303302

303+
#[rustversion::since(1.62)]
304304
/// Compare between itself and other GpsTime
305-
/// Checks whether week number is same which then mirrors [`https://github.com/rust-lang/rust/blob/481db40311cdd241ae4d33f34f2f75732e44d8e8/library/core/src/num/f64.rs#L1228`](f64::total_cmp())
306-
pub fn total_cmp(&self, other: &GpsTime) -> Ordering {
305+
/// Checks whether week number is same which then mirrors
306+
/// [f64::total_cmp()](https://doc.rust-lang.org/std/primitive.f64.html#method.total_cmp)
307+
pub fn total_cmp(&self, other: &GpsTime) -> std::cmp::Ordering {
307308
if self.wn() != other.wn() {
308309
self.wn().cmp(&other.wn())
309310
} else {
310-
//TODO: replace with f64::total_cmp
311-
let mut left = self.tow().to_bits() as i64;
312-
let mut right = other.tow().to_bits() as i64;
313-
314-
left ^= (((left >> 63) as u64) >> 1) as i64;
315-
right ^= (((right >> 63) as u64) >> 1) as i64;
316-
317-
left.cmp(&right)
311+
let other = other.tow();
312+
self.tow().total_cmp(&other)
318313
}
319314
}
320315
}
@@ -922,6 +917,26 @@ mod tests {
922917
assert!(t3 >= t3);
923918
}
924919

920+
#[rustversion::since(1.62)]
921+
#[test]
922+
fn total_order() {
923+
use std::cmp::Ordering;
924+
925+
let t1 = GpsTime::new(10, 234.566).unwrap();
926+
let t2 = GpsTime::new(10, 234.567).unwrap();
927+
let t3 = GpsTime::new(10, 234.568).unwrap();
928+
929+
assert!(t1.total_cmp(&t2) == Ordering::Less);
930+
assert!(t2.total_cmp(&t3) == Ordering::Less);
931+
assert!(t1.total_cmp(&t3) == Ordering::Less);
932+
933+
assert!(t2.total_cmp(&t1) == Ordering::Greater);
934+
assert!(t3.total_cmp(&t2) == Ordering::Greater);
935+
assert!(t3.total_cmp(&t1) == Ordering::Greater);
936+
937+
assert!(t1.total_cmp(&t1) == Ordering::Equal);
938+
}
939+
925940
#[test]
926941
fn add_duration() {
927942
let mut t = GpsTime::new(0, 0.0).unwrap();

0 commit comments

Comments
 (0)