1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::cmp;
use std::fmt;
use std::path;


#[derive(Clone, Debug)]
pub struct Entry {
    pub path: path::PathBuf,
    pub weight: f64,
}


impl Entry {
    pub fn new<P>(path: P, weight: f64) -> Entry
        where P: Into<path::PathBuf>
    {
        Entry {
            path: path.into(),
            weight: weight,
        }
    }
}


impl fmt::Display for Entry {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{:.1}:\t{}", self.weight, self.path.to_string_lossy())
    }
}


impl AsRef<path::Path> for Entry {
    fn as_ref(&self) -> &path::Path {
        self.path.as_path()
    }
}


impl PartialOrd for Entry {
    fn partial_cmp(&self, other: &Entry) -> Option<cmp::Ordering> {
        self.weight.partial_cmp(&other.weight)
    }
}


impl PartialEq for Entry {
    fn eq(&self, other: &Entry) -> bool {
        self.weight == other.weight
    }
}


impl Eq for Entry {}


impl Ord for Entry {
    fn cmp(&self, other: &Entry) -> cmp::Ordering {
        // We know that NaN's don't exist in our use case, so just unwrap it.
        self.partial_cmp(other).unwrap()
    }
}