From 28101de56231252ca0cfa6a9f107b75112c9acad Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Wed, 31 Jan 2024 07:38:50 +1300 Subject: 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. --- src/devices/file/directory_entry.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/devices/file/directory_entry.rs (limited to 'src/devices/file/directory_entry.rs') 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, + pub entry_type: EntryType, +} + +impl PartialOrd for DirectoryChild { + fn partial_cmp(&self, other: &Self) -> Option { + 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, + } + } +} -- cgit v1.2.3-70-g09d2