simple_fs/safer_remove/
safer_remove_options.rs

1#[derive(Debug, Clone)]
2pub struct SaferRemoveOptions<'a> {
3	pub must_contain_any: Option<&'a [&'a str]>,
4	pub must_contain_all: Option<&'a [&'a str]>,
5	pub restrict_to_current_dir: bool,
6}
7
8// region:    --- Default
9
10impl Default for SaferRemoveOptions<'_> {
11	fn default() -> Self {
12		Self {
13			must_contain_any: None,
14			must_contain_all: None,
15			restrict_to_current_dir: true,
16		}
17	}
18}
19
20// endregion: --- Default
21
22// region:    --- Froms
23
24impl From<()> for SaferRemoveOptions<'_> {
25	fn from(_: ()) -> Self {
26		Self::default()
27	}
28}
29
30impl<'a> From<&'a [&'a str]> for SaferRemoveOptions<'a> {
31	fn from(patterns: &'a [&'a str]) -> Self {
32		Self {
33			must_contain_any: Some(patterns),
34			..Default::default()
35		}
36	}
37}
38
39// endregion: --- Froms
40
41// region:    --- Fluent API
42
43impl<'a> SaferRemoveOptions<'a> {
44	pub fn with_must_contain_any(mut self, patterns: &'a [&'a str]) -> Self {
45		self.must_contain_any = Some(patterns);
46		self
47	}
48
49	pub fn with_must_contain_all(mut self, patterns: &'a [&'a str]) -> Self {
50		self.must_contain_all = Some(patterns);
51		self
52	}
53
54	pub fn with_restrict_to_current_dir(mut self, val: bool) -> Self {
55		self.restrict_to_current_dir = val;
56		self
57	}
58}
59
60// endregion: --- Fluent API