ncollide3d/utils/
ref_with_cost.rs
1use std::cmp::Ordering;
4
5pub struct RefWithCost<'a, N, T: 'a> {
7 pub object: &'a T,
9 pub cost: N,
11}
12
13impl<'a, N, T> RefWithCost<'a, N, T> {
14 #[inline]
16 pub fn new(object: &'a T, cost: N) -> RefWithCost<'a, N, T> {
17 RefWithCost {
18 object: object,
19 cost: cost,
20 }
21 }
22}
23
24impl<'a, N: PartialEq, T> PartialEq for RefWithCost<'a, N, T> {
25 #[inline]
26 fn eq(&self, other: &RefWithCost<'a, N, T>) -> bool {
27 self.cost.eq(&other.cost)
28 }
29}
30
31impl<'a, N: PartialEq, T> Eq for RefWithCost<'a, N, T> {}
32
33impl<'a, N: PartialOrd, T> PartialOrd for RefWithCost<'a, N, T> {
34 #[inline]
35 fn partial_cmp(&self, other: &RefWithCost<'a, N, T>) -> Option<Ordering> {
36 self.cost.partial_cmp(&other.cost)
37 }
38}
39
40impl<'a, N: PartialOrd, T> Ord for RefWithCost<'a, N, T> {
41 #[inline]
42 fn cmp(&self, other: &RefWithCost<'a, N, T>) -> Ordering {
43 if self.cost < other.cost {
44 Ordering::Less
45 } else if self.cost > other.cost {
46 Ordering::Greater
47 } else {
48 Ordering::Equal
49 }
50 }
51}