Skip to main content

trillium_static_compiled/
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 Durations 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    /// Create a new Metadata from the number of seconds since the epoch
23    pub const fn from_secs(accessed: u64, created: u64, modified: u64) -> Self {
24        Self::new(
25            Duration::from_secs(accessed),
26            Duration::from_secs(created),
27            Duration::from_secs(modified),
28        )
29    }
30
31    /// Get the time this file was last accessed.
32    ///
33    /// See also: [`std::fs::Metadata::accessed()`].
34    pub fn accessed(&self) -> SystemTime {
35        SystemTime::UNIX_EPOCH + self.accessed
36    }
37
38    /// Get the time this file was created.
39    ///
40    /// See also: [`std::fs::Metadata::created()`].
41    pub fn created(&self) -> SystemTime {
42        SystemTime::UNIX_EPOCH + self.created
43    }
44
45    /// Get the time this file was last modified.
46    ///
47    /// See also: [`std::fs::Metadata::modified()`].
48    pub fn modified(&self) -> SystemTime {
49        SystemTime::UNIX_EPOCH + self.modified
50    }
51}