summaryrefslogtreecommitdiff
path: root/src/types/entry_type.rs
blob: 6a9ac2d39a3460a826bc7a524343f9ca8c8f2aa1 (plain) (blame)
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
use crate::*;

use std::cmp::Ordering;


pub enum Entry {
    File(BufferedFile),
    Directory(DirectoryListing),
}

#[derive(Copy, Clone, PartialEq, Eq)]
pub enum EntryType {
    File,
    Directory,
}

impl PartialOrd for EntryType {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        match (self, other) {
            (EntryType::Directory, EntryType::Directory) => Some(Ordering::Equal  ),
            (EntryType::Directory, EntryType::File     ) => Some(Ordering::Less   ),
            (EntryType::File,      EntryType::Directory) => Some(Ordering::Greater),
            (EntryType::File,      EntryType::File     ) => Some(Ordering::Equal  ),
        }
    }
}

impl Ord for EntryType {
    fn cmp(&self, other: &Self) -> Ordering {
        match (self, other) {
            (EntryType::Directory, EntryType::Directory) => Ordering::Equal  ,
            (EntryType::Directory, EntryType::File     ) => Ordering::Less   ,
            (EntryType::File,      EntryType::Directory) => Ordering::Greater,
            (EntryType::File,      EntryType::File     ) => Ordering::Equal  ,
        }
    }
}