systemprompt_extension/
asset.rs1use std::path::{Path, PathBuf};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum AssetType {
5 Css,
6 Image,
7 Font,
8 JavaScript,
9}
10
11#[derive(Debug, Clone)]
12pub struct AssetDefinition {
13 source: PathBuf,
14 destination: &'static str,
15 asset_type: AssetType,
16 required: bool,
17}
18
19#[derive(Debug)]
20pub struct AssetDefinitionBuilder {
21 source: PathBuf,
22 destination: &'static str,
23 asset_type: AssetType,
24 required: bool,
25}
26
27impl AssetDefinitionBuilder {
28 pub fn new(
29 source: impl Into<PathBuf>,
30 destination: &'static str,
31 asset_type: AssetType,
32 ) -> Self {
33 Self {
34 source: source.into(),
35 destination,
36 asset_type,
37 required: true,
38 }
39 }
40
41 #[must_use]
42 pub const fn optional(mut self) -> Self {
43 self.required = false;
44 self
45 }
46
47 #[must_use]
48 pub fn build(self) -> AssetDefinition {
49 AssetDefinition {
50 source: self.source,
51 destination: self.destination,
52 asset_type: self.asset_type,
53 required: self.required,
54 }
55 }
56}
57
58impl AssetDefinition {
59 pub fn builder(
60 source: impl Into<PathBuf>,
61 destination: &'static str,
62 asset_type: AssetType,
63 ) -> AssetDefinitionBuilder {
64 AssetDefinitionBuilder::new(source, destination, asset_type)
65 }
66
67 #[must_use]
68 pub fn css(source: impl Into<PathBuf>, destination: &'static str) -> Self {
69 Self::builder(source, destination, AssetType::Css).build()
70 }
71
72 #[must_use]
73 pub fn image(source: impl Into<PathBuf>, destination: &'static str) -> Self {
74 Self::builder(source, destination, AssetType::Image).build()
75 }
76
77 #[must_use]
78 pub fn font(source: impl Into<PathBuf>, destination: &'static str) -> Self {
79 Self::builder(source, destination, AssetType::Font).build()
80 }
81
82 #[must_use]
83 pub fn javascript(source: impl Into<PathBuf>, destination: &'static str) -> Self {
84 Self::builder(source, destination, AssetType::JavaScript).build()
85 }
86
87 #[must_use]
88 pub fn source(&self) -> &Path {
89 &self.source
90 }
91
92 #[must_use]
93 pub const fn destination(&self) -> &str {
94 self.destination
95 }
96
97 #[must_use]
98 pub const fn asset_type(&self) -> AssetType {
99 self.asset_type
100 }
101
102 #[must_use]
103 pub const fn is_required(&self) -> bool {
104 self.required
105 }
106}