1use std::cmp::Ordering;
4use std::collections::BTreeMap;
5use std::fmt;
6
7use ordered::{ArbitraryOrd, Ordered};
8
9fn main() {
10 let mut map = BTreeMap::new();
11
12 let a = Point { x: 2, y: 3 };
13 let b = Point { x: 1, y: 5 };
14
15 map.insert(Ordered::from(a), "some interesting value");
16 map.insert(Ordered::from(b), "some other interesting value");
17
18 println!();
19 println!("Looking in map for key: {}", a);
20
21 let found = map.get(Ordered::from_ref(&a)).expect("handle item not found");
22
23 println!("Found it, with value: {}", found);
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30struct Point {
31 x: u32,
32 y: u32,
33}
34
35impl ArbitraryOrd for Point {
36 fn arbitrary_cmp(&self, other: &Self) -> Ordering { (self.x, self.y).cmp(&(other.x, other.y)) }
37}
38
39impl fmt::Display for Point {
40 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "({}, {})", self.x, self.y) }
41}