rust_embed_for_web_utils/file/
embed.rs1use super::common::EmbedableFile;
2use std::fmt::Debug;
3
4#[derive(Clone, Copy)]
13pub struct EmbeddedFile {
14 name: &'static str,
15 data: &'static [u8],
16 data_gzip: Option<&'static [u8]>,
17 data_br: Option<&'static [u8]>,
18 hash: &'static str,
19 etag: &'static str,
20 last_modified: Option<&'static str>,
21 last_modified_timestamp: Option<i64>,
22 mime_type: Option<&'static str>,
23}
24
25impl EmbedableFile for EmbeddedFile {
26 type Data = &'static [u8];
27 type Meta = &'static str;
28
29 fn name(&self) -> Self::Meta {
30 self.name
31 }
32
33 fn data(&self) -> Self::Data {
34 self.data
35 }
36
37 fn data_gzip(&self) -> Option<Self::Data> {
38 self.data_gzip
39 }
40
41 fn data_br(&self) -> Option<Self::Data> {
42 self.data_br
43 }
44
45 fn last_modified(&self) -> Option<Self::Meta> {
46 self.last_modified
47 }
48
49 fn last_modified_timestamp(&self) -> Option<i64> {
50 self.last_modified_timestamp
51 }
52
53 fn hash(&self) -> Self::Meta {
54 self.hash
55 }
56
57 fn etag(&self) -> Self::Meta {
58 self.etag
59 }
60
61 fn mime_type(&self) -> Option<Self::Meta> {
62 self.mime_type
63 }
64}
65
66impl EmbeddedFile {
67 #[doc(hidden)]
68 #[allow(clippy::too_many_arguments)]
69 pub fn __internal_make(
72 name: &'static str,
76 data: &'static [u8],
77 data_gzip: Option<&'static [u8]>,
78 data_br: Option<&'static [u8]>,
79 hash: &'static str,
80 etag: &'static str,
81 last_modified: Option<&'static str>,
82 last_modified_timestamp: Option<i64>,
83 mime_type: Option<&'static str>,
84 ) -> EmbeddedFile {
85 EmbeddedFile {
86 name,
87 data,
88 data_gzip,
89 data_br,
90 hash,
91 etag,
92 last_modified,
93 last_modified_timestamp,
94 mime_type,
95 }
96 }
97}
98
99impl Debug for EmbeddedFile {
100 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
101 f.debug_struct("EmbeddedFile")
102 .field("name", &self.name)
103 .field("hash", &self.hash)
104 .field("last_modified", &self.last_modified())
105 .field("mime_type", &self.mime_type)
106 .finish()
107 }
108}
109
110impl PartialEq for EmbeddedFile {
111 fn eq(&self, other: &Self) -> bool {
112 self.hash.eq(other.hash)
113 }
114}