cobble_core/minecraft/screenshots/
screenshot.rs

1use crate::error::CobbleResult;
2use std::path::PathBuf;
3use time::OffsetDateTime;
4use tokio::fs::remove_file;
5
6/// Represents a single screenshot.
7#[cfg_attr(doc_cfg, doc(cfg(feature = "screenshots")))]
8#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
9#[derive(Clone, Debug)]
10pub struct Screenshot {
11    /// Name of the save game
12    pub name: String,
13    /// Path to the save game
14    pub path: PathBuf,
15    /// Created timestamp
16    #[cfg_attr(feature = "serde", serde(with = "time::serde::rfc3339::option"))]
17    pub created: Option<OffsetDateTime>,
18}
19
20impl Screenshot {
21    /// Removes the screenshot from disk.
22    ///
23    /// **Warning**: This will permanently delete the file!
24    #[instrument(
25        name = "remove_screenshot",
26        level = "trace",
27        skip_all,
28        fields(
29            name,
30            path = %self.path.to_string_lossy(),
31        )
32    )]
33    pub async fn remove(self) -> CobbleResult<()> {
34        remove_file(&self.path).await?;
35        Ok(())
36    }
37}