cap_fs_ext/
dir_entry_ext.rs

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use cap_primitives::fs::Metadata;
#[cfg(windows)]
use cap_primitives::fs::_WindowsDirEntryExt;
use std::io;

/// Extension trait for `DirEntry`.
pub trait DirEntryExt {
    /// Return the full metadata, which on Windows includes the optional
    /// values.
    ///
    /// If the full metadata cannot be computed, this fails rather than
    /// falling back to partial metadata, even when that might not fail.
    /// If partial metadata is desired, `std::fs::DirEntry::metadata` can
    /// be used.
    fn full_metadata(&self) -> io::Result<Metadata>;
}

#[cfg(not(windows))]
impl DirEntryExt for std::fs::DirEntry {
    #[inline]
    fn full_metadata(&self) -> io::Result<Metadata> {
        self.metadata().map(Metadata::from_just_metadata)
    }
}

#[cfg(all(not(windows), feature = "std"))]
impl DirEntryExt for cap_std::fs::DirEntry {
    #[inline]
    fn full_metadata(&self) -> io::Result<Metadata> {
        self.metadata()
    }
}

#[cfg(all(windows, feature = "std"))]
impl DirEntryExt for cap_std::fs::DirEntry {
    #[inline]
    fn full_metadata(&self) -> io::Result<Metadata> {
        _WindowsDirEntryExt::full_metadata(self)
    }
}

#[cfg(all(not(windows), feature = "async_std"))]
impl DirEntryExt for cap_async_std::fs::DirEntry {
    #[inline]
    fn full_metadata(&self) -> io::Result<Metadata> {
        self.metadata()
    }
}

#[cfg(all(windows, feature = "async_std"))]
impl DirEntryExt for cap_async_std::fs::DirEntry {
    #[inline]
    fn full_metadata(&self) -> io::Result<Metadata> {
        _WindowsDirEntryExt::full_metadata(self)
    }
}

#[cfg(all(not(windows), feature = "std", feature = "fs_utf8"))]
impl DirEntryExt for cap_std::fs_utf8::DirEntry {
    #[inline]
    fn full_metadata(&self) -> io::Result<Metadata> {
        self.metadata()
    }
}

#[cfg(all(windows, feature = "std", feature = "fs_utf8"))]
impl DirEntryExt for cap_std::fs_utf8::DirEntry {
    #[inline]
    fn full_metadata(&self) -> io::Result<Metadata> {
        _WindowsDirEntryExt::full_metadata(self)
    }
}

#[cfg(all(not(windows), feature = "async_std", feature = "fs_utf8"))]
impl DirEntryExt for cap_async_std::fs_utf8::DirEntry {
    #[inline]
    fn full_metadata(&self) -> io::Result<Metadata> {
        self.metadata()
    }
}

#[cfg(all(windows, feature = "async_std", feature = "fs_utf8"))]
impl DirEntryExt for cap_async_std::fs_utf8::DirEntry {
    #[inline]
    fn full_metadata(&self) -> io::Result<Metadata> {
        _WindowsDirEntryExt::full_metadata(self)
    }
}