include_dir/metadata.rs
1use std::time::{Duration, SystemTime};
2
3/// Basic metadata for a file.
4#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5pub struct Metadata {
6 accessed: Duration,
7 created: Duration,
8 modified: Duration,
9}
10
11impl Metadata {
12 /// Create a new [`Metadata`] using the number of seconds since the
13 /// [`SystemTime::UNIX_EPOCH`].
14 pub const fn new(accessed: Duration, created: Duration, modified: Duration) -> Self {
15 Metadata {
16 accessed,
17 created,
18 modified,
19 }
20 }
21
22 /// Get the time this file was last accessed.
23 ///
24 /// See also: [`std::fs::Metadata::accessed()`].
25 pub fn accessed(&self) -> SystemTime {
26 SystemTime::UNIX_EPOCH + self.accessed
27 }
28
29 /// Get the time this file was created.
30 ///
31 /// See also: [`std::fs::Metadata::created()`].
32 pub fn created(&self) -> SystemTime {
33 SystemTime::UNIX_EPOCH + self.created
34 }
35
36 /// Get the time this file was last modified.
37 ///
38 /// See also: [`std::fs::Metadata::modified()`].
39 pub fn modified(&self) -> SystemTime {
40 SystemTime::UNIX_EPOCH + self.modified
41 }
42}