1use rand::{distr::Alphanumeric, rng, Rng};
2
3use std::env;
4use std::path::PathBuf;
5
6#[cfg(feature = "yaml")]
7use serde::Deserialize;
8#[cfg(feature = "yaml")]
9use serde::Serialize;
10
11#[derive(Debug)]
13pub struct Tree {
14 pub root: PathBuf,
16 pub drop: bool,
18}
19
20impl Drop for Tree {
21 fn drop(&mut self) {
22 if self.drop {
23 let _ = std::fs::remove_dir_all(&self.root);
24 }
25 }
26}
27
28#[derive(Debug, Clone)]
31#[cfg_attr(feature = "yaml", derive(Deserialize, Serialize))]
32#[derive(Default)]
33pub struct Settings {
34 #[cfg_attr(
36 feature = "yaml",
37 serde(default, skip_serializing_if = "std::ops::Not::not")
38 )]
39 pub readonly: bool,
40 }
45
46impl Settings {
48 #[must_use]
50 pub fn new() -> Self {
51 Self::default()
52 }
53
54 #[must_use]
56 pub const fn readonly(mut self, value: bool) -> Self {
57 self.readonly = value;
58 self
59 }
60}
61
62#[derive(Debug, Clone)]
64#[cfg_attr(feature = "yaml", derive(Deserialize))]
65#[cfg_attr(feature = "yaml", serde(tag = "type"))]
66pub enum Kind {
67 #[cfg_attr(feature = "yaml", serde(rename = "directory"))]
69 Directory,
70 #[cfg_attr(feature = "yaml", serde(rename = "empty_file"))]
72 EmptyFile,
73 #[cfg_attr(feature = "yaml", serde(rename = "text_file"))]
75 TextFile { content: String },
76}
77
78#[derive(Debug)]
80#[cfg_attr(feature = "yaml", derive(Deserialize))]
81pub struct Entry {
82 pub path: PathBuf,
84 #[cfg_attr(feature = "yaml", serde(flatten))]
86 pub kind: Kind,
87 #[cfg_attr(
89 feature = "yaml",
90 serde(default, skip_serializing_if = "Option::is_none")
91 )]
92 pub settings: Option<Settings>,
93}
94
95pub fn temp_dir() -> PathBuf {
97 let random_string: String = rng()
98 .sample_iter(&Alphanumeric)
99 .take(5)
100 .map(char::from)
101 .collect();
102
103 env::temp_dir().join(random_string)
104}