diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-01-31 07:38:50 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-01-31 07:39:07 +1300 |
commit | 28101de56231252ca0cfa6a9f107b75112c9acad (patch) | |
tree | f5c82a6894562bfb8ed8ab94e9345cefaa6fb96b /src/devices/file/directory_entry.rs | |
parent | 30d2f099c9edf4f59fbbdd6686988ae7b0622ba2 (diff) | |
download | bedrock-pc-28101de56231252ca0cfa6a9f107b75112c9acad.zip |
Implement new file device interface
This is a complete redesign of the file device. The most notable
addition is the ability to ascend and descend the file tree.
Diffstat (limited to 'src/devices/file/directory_entry.rs')
-rw-r--r-- | src/devices/file/directory_entry.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/devices/file/directory_entry.rs b/src/devices/file/directory_entry.rs new file mode 100644 index 0000000..45de817 --- /dev/null +++ b/src/devices/file/directory_entry.rs @@ -0,0 +1,30 @@ +use crate::*; + +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, + } + } +} |