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
use crate::sys;
use chrono::{offset::TimeZone, DateTime, Utc};

/// File Metadata
///
/// <https://discordapp.com/developers/docs/game-sdk/storage#data-models-filestat-struct>
#[derive(Clone, Copy, Eq, PartialEq, derive_more::From, derive_more::Into)]
pub struct FileStat(pub(crate) sys::DiscordFileStat);

impl FileStat {
    get_str!(filename, filename);

    pub fn size(&self) -> u64 {
        self.0.size
    }

    pub fn last_modified(&self) -> DateTime<Utc> {
        Utc.timestamp(self.0.last_modified as i64, 0)
    }
}

impl std::fmt::Debug for FileStat {
    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        fmt.debug_struct("FileStat")
            .field("filename", &self.filename())
            .field("size", &self.size())
            .field("last_modified", &self.last_modified())
            .finish()
    }
}