1use derive_more::Constructor;
2use std::path::{Path, PathBuf};
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum FileType {
6 File,
7 Dir,
8 Symlink,
9}
10
11#[cfg(feature = "vfs")]
14impl From<FileType> for vfs::VfsFileType {
15 fn from(f: FileType) -> Self {
16 match f {
17 FileType::File | FileType::Symlink => vfs::VfsFileType::File,
18 FileType::Dir => vfs::VfsFileType::Directory,
19 }
20 }
21}
22
23#[derive(Clone, Debug, Constructor)]
24pub struct Metadata {
25 pub file_type: FileType,
26 pub len: u64,
27 pub target_path: Option<PathBuf>,
28}
29
30impl Metadata {
31 #[inline]
32 pub const fn file(len: u64) -> Self {
33 Self::new(FileType::File, len, None)
34 }
35
36 #[inline]
37 pub const fn directory() -> Self {
38 Self::new(FileType::Dir, 0, None)
39 }
40
41 #[inline]
42 pub fn symlink<P: AsRef<Path>>(target: Metadata, target_path: P) -> Self {
43 let target_path = Some(target_path.as_ref().to_path_buf());
44 Self::new(FileType::Symlink, target.len, target_path)
45 }
46}
47
48#[cfg(feature = "vfs")]
49impl From<Metadata> for vfs::VfsMetadata {
50 fn from(m: Metadata) -> Self {
51 vfs::VfsMetadata { file_type: m.file_type.into(), len: m.len, created: None, modified: None, accessed: None }
52 }
53}