Skip to content

Commit

Permalink
test Send Sync
Browse files Browse the repository at this point in the history
Copy test from Rust API guidlines document to verify `Send` and `Sync`
are correct.
  • Loading branch information
tcharding committed Dec 29, 2024
1 parent 20cc4a5 commit c6ac14b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,26 @@ mod tests {

assert!(Ordered(&a) < Ordered(&b));
}

// Copied from https://rust-lang.github.io/api-guidelines/interoperability.html#c-send-sync
#[test]
fn send() {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct Point {
x: u32,
y: u32,
}

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

fn assert_send<T: Send>() {}
fn assert_sync<T: Sync>() {}

assert_send::<Ordered<Point>>();
assert_sync::<Ordered<Point>>();
}
}

0 comments on commit c6ac14b

Please sign in to comment.