summaryrefslogtreecommitdiff
path: root/src/devices/file/directory_entry.rs
blob: c4ce14645022abfac42e3fc047656c64d70cc90c (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
use super::*;

use std::cmp::Ordering;

#[derive(PartialEq, Eq)]
pub struct DirectoryChild {
    pub byte_path: Vec<u8>,
    pub entry_type: EntryType,
}

impl PartialOrd for DirectoryChild {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        let entry_type_ord = self.entry_type.cmp(&other.entry_type);
        let final_order = match entry_type_ord {
            Ordering::Equal => self.byte_path.cmp(&other.byte_path),
            _ => entry_type_ord,
        };
        Some(final_order)
    }
}

impl Ord for DirectoryChild {
    fn cmp(&self, other: &Self) -> Ordering {
        let entry_type_ord = self.entry_type.cmp(&other.entry_type);
        match entry_type_ord {
            Ordering::Equal => self.byte_path.cmp(&other.byte_path),
            _ => entry_type_ord,
        }
    }
}