Skip to content

Commit

Permalink
Merge pull request #20 from tcharding/12-29-fmt-in-ci
Browse files Browse the repository at this point in the history
CI: Run the formatter
  • Loading branch information
tcharding authored Dec 29, 2024
2 parents 8e9afdb + d1fab05 commit 9840ef6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,18 @@ jobs:
run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock
- name: "Run test script"
run: ./maintainer-tools/ci/run_task.sh docsrs

Format: # 1 job, run cargo fmt directly.
name: Format - nightly toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
- name: "Select toolchain"
uses: dtolnay/rust-toolchain@nightly
- name: "Install rustfmt"
run: rustup component add rustfmt
- name: "Check formatting"
run: cargo +nightly fmt --all -- --check
4 changes: 3 additions & 1 deletion examples/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ fn main() {

println!();
println!("Looking in map for key: {}", a);
let found = map.get(Ordered::from_ref(&a)).expect("failed to look up key");
let found = map
.get(Ordered::from_ref(&a))
.expect("failed to look up key");
println!("Found it, with value: {}", found);
}

Expand Down
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,11 @@ impl<T> Ordered<T> {
/// Creates an `Ordered<T>` from a reference.
///
/// This allows: `let found = map.get(Ordered::from_ref(&a));`
pub fn from_ref(value: &T) -> &Self {
unsafe { &*(value as *const _ as *const Self) }
}
pub fn from_ref(value: &T) -> &Self { unsafe { &*(value as *const _ as *const Self) } }
}

impl<T: ArbitraryOrd> ArbitraryOrd for &T {
fn arbitrary_cmp(&self, other: &Self) -> Ordering {
(*self).arbitrary_cmp(other)
}
fn arbitrary_cmp(&self, other: &Self) -> Ordering { (*self).arbitrary_cmp(other) }
}

impl<T: ArbitraryOrd> PartialOrd for Ordered<T> {
Expand Down Expand Up @@ -155,7 +151,9 @@ mod tests {
}

impl ArbitraryOrd for Point {
fn arbitrary_cmp(&self, other: &Self) -> Ordering { (self.x, self.y).cmp(&(other.x, other.y)) }
fn arbitrary_cmp(&self, other: &Self) -> Ordering {
(self.x, self.y).cmp(&(other.x, other.y))
}
}

#[test]
Expand Down

0 comments on commit 9840ef6

Please sign in to comment.