Skip to main content

rama_utils/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    #[must_use]
15    pub const fn new(accessed: Duration, created: Duration, modified: Duration) -> Self {
16        Self {
17            accessed,
18            created,
19            modified,
20        }
21    }
22
23    /// Get the time this file was last accessed.
24    ///
25    /// See also: [`std::fs::Metadata::accessed()`].
26    #[must_use]
27    pub fn accessed(&self) -> SystemTime {
28        SystemTime::UNIX_EPOCH + self.accessed
29    }
30
31    /// Get the time this file was created.
32    ///
33    /// See also: [`std::fs::Metadata::created()`].
34    #[must_use]
35    pub fn created(&self) -> SystemTime {
36        SystemTime::UNIX_EPOCH + self.created
37    }
38
39    /// Get the time this file was last modified.
40    ///
41    /// See also: [`std::fs::Metadata::modified()`].
42    #[must_use]
43    pub fn modified(&self) -> SystemTime {
44        SystemTime::UNIX_EPOCH + self.modified
45    }
46}