1use crate::{
2 directory::EntryType,
3 error::{Error, Result},
4 file::File,
5 joint_directory::JointDirectory,
6};
7
8#[derive(Debug)]
9pub enum JointEntry {
10 File(File),
11 Directory(JointDirectory),
12}
13
14#[allow(clippy::len_without_is_empty)]
15impl JointEntry {
16 pub fn entry_type(&self) -> EntryType {
17 match self {
18 Self::File(_) => EntryType::File,
19 Self::Directory(_) => EntryType::Directory,
20 }
21 }
22
23 pub fn as_file_mut(&mut self) -> Result<&mut File> {
24 match self {
25 Self::File(file) => Ok(file),
26 Self::Directory(_) => Err(Error::EntryIsDirectory),
27 }
28 }
29
30 pub fn as_directory(&self) -> Result<&JointDirectory> {
31 match self {
32 Self::File(_) => Err(Error::EntryIsFile),
33 Self::Directory(dirs) => Ok(dirs),
34 }
35 }
36
37 pub fn as_directory_mut(&mut self) -> Result<&mut JointDirectory> {
38 match self {
39 Self::File(_) => Err(Error::EntryIsFile),
40 Self::Directory(dirs) => Ok(dirs),
41 }
42 }
43
44 pub fn len(&self) -> u64 {
46 match self {
47 Self::File(file) => file.len(),
48 Self::Directory(dir) => dir.len(),
49 }
50 }
51}