1use alloc::{format, string::String, string::ToString, vec, vec::Vec};
7
8use super::{CodegenBackend, GeneratedFile};
9use crate::{
10 css::{
11 AttributeMatchOp, Css, CssAttributeSelector, CssDeclaration, CssNthChildPattern,
12 CssNthChildSelector, CssPath, CssPathPseudoSelector, CssPathSelector, DynamicCssProperty,
13 NodeTypeTag,
14 },
15 props::property::format_static_css_prop,
16};
17
18pub struct RustBackend;
20
21impl CodegenBackend for RustBackend {
22 fn lang(&self) -> &'static str {
23 "rust"
24 }
25
26 fn emit_css(&self, css: &Css) -> String {
27 css_to_rust_code(css)
28 }
29
30 fn emit_project(&self, css: &Css) -> Vec<GeneratedFile> {
31 let css_literal = css_to_rust_code(css);
32 let main_rs = format!(
33 "use azul::prelude::*;\r\n\r\n{css_literal}\r\n\r\nfn main() {{\r\n \
34 println!(\"Generated stylesheet contains {{}} rule(s)\", \
35 CSS.rules.as_ref().len());\r\n}}\r\n",
36 );
37 let cargo_toml = "[package]\r\n\
38 name = \"azul-generated-app\"\r\n\
39 version = \"0.1.0\"\r\n\
40 edition = \"2021\"\r\n\
41 \r\n\
42 [dependencies]\r\n\
43 azul = \"0.0.7\"\r\n"
44 .to_string();
45 vec![
46 GeneratedFile {
47 path: "Cargo.toml".to_string(),
48 contents: cargo_toml,
49 },
50 GeneratedFile {
51 path: "src/main.rs".to_string(),
52 contents: main_rs,
53 },
54 ]
55 }
56}
57
58pub fn css_to_rust_code(css: &Css) -> String {
60 let mut output = String::new();
61
62 output.push_str("const CSS: Css = Css {\r\n");
63 output.push_str("\trules: [\r\n");
64
65 for block in css.rules.iter() {
66 output.push_str("\t\tCssRuleBlock {\r\n");
67 output.push_str(&format!(
68 "\t\t\tpath: {},\r\n",
69 print_block_path(&block.path, 3)
70 ));
71 output.push_str(&format!(
72 "\t\t\tpriority: {},\r\n",
73 block.priority,
74 ));
75
76 output.push_str("\t\t\tdeclarations: [\r\n");
77 for declaration in block.declarations.iter() {
78 output.push_str(&format!(
79 "\t\t\t\t{},\r\n",
80 print_declaration(declaration, 4)
81 ));
82 }
83 output.push_str("\t\t\t]\r\n");
84
85 output.push_str("\t\t},\r\n");
86 }
87
88 output.push_str("\t]\r\n");
89 output.push_str("};");
90
91 output.replace("\t", " ")
92}
93
94pub fn format_node_type(n: &NodeTypeTag) -> &'static str {
95 match n {
96 NodeTypeTag::Html => "NodeTypeTag::Html",
98 NodeTypeTag::Head => "NodeTypeTag::Head",
99 NodeTypeTag::Body => "NodeTypeTag::Body",
100
101 NodeTypeTag::Div => "NodeTypeTag::Div",
103 NodeTypeTag::P => "NodeTypeTag::P",
104 NodeTypeTag::Article => "NodeTypeTag::Article",
105 NodeTypeTag::Section => "NodeTypeTag::Section",
106 NodeTypeTag::Nav => "NodeTypeTag::Nav",
107 NodeTypeTag::Aside => "NodeTypeTag::Aside",
108 NodeTypeTag::Header => "NodeTypeTag::Header",
109 NodeTypeTag::Footer => "NodeTypeTag::Footer",
110 NodeTypeTag::Main => "NodeTypeTag::Main",
111 NodeTypeTag::Figure => "NodeTypeTag::Figure",
112 NodeTypeTag::FigCaption => "NodeTypeTag::FigCaption",
113
114 NodeTypeTag::H1 => "NodeTypeTag::H1",
116 NodeTypeTag::H2 => "NodeTypeTag::H2",
117 NodeTypeTag::H3 => "NodeTypeTag::H3",
118 NodeTypeTag::H4 => "NodeTypeTag::H4",
119 NodeTypeTag::H5 => "NodeTypeTag::H5",
120 NodeTypeTag::H6 => "NodeTypeTag::H6",
121
122 NodeTypeTag::Br => "NodeTypeTag::Br",
124 NodeTypeTag::Hr => "NodeTypeTag::Hr",
125 NodeTypeTag::Pre => "NodeTypeTag::Pre",
126 NodeTypeTag::BlockQuote => "NodeTypeTag::BlockQuote",
127 NodeTypeTag::Address => "NodeTypeTag::Address",
128 NodeTypeTag::Details => "NodeTypeTag::Details",
129 NodeTypeTag::Summary => "NodeTypeTag::Summary",
130 NodeTypeTag::Dialog => "NodeTypeTag::Dialog",
131
132 NodeTypeTag::Ul => "NodeTypeTag::Ul",
134 NodeTypeTag::Ol => "NodeTypeTag::Ol",
135 NodeTypeTag::Li => "NodeTypeTag::Li",
136 NodeTypeTag::Dl => "NodeTypeTag::Dl",
137 NodeTypeTag::Dt => "NodeTypeTag::Dt",
138 NodeTypeTag::Dd => "NodeTypeTag::Dd",
139 NodeTypeTag::Menu => "NodeTypeTag::Menu",
140 NodeTypeTag::MenuItem => "NodeTypeTag::MenuItem",
141 NodeTypeTag::Dir => "NodeTypeTag::Dir",
142
143 NodeTypeTag::Table => "NodeTypeTag::Table",
145 NodeTypeTag::Caption => "NodeTypeTag::Caption",
146 NodeTypeTag::THead => "NodeTypeTag::THead",
147 NodeTypeTag::TBody => "NodeTypeTag::TBody",
148 NodeTypeTag::TFoot => "NodeTypeTag::TFoot",
149 NodeTypeTag::Tr => "NodeTypeTag::Tr",
150 NodeTypeTag::Th => "NodeTypeTag::Th",
151 NodeTypeTag::Td => "NodeTypeTag::Td",
152 NodeTypeTag::ColGroup => "NodeTypeTag::ColGroup",
153 NodeTypeTag::Col => "NodeTypeTag::Col",
154
155 NodeTypeTag::Form => "NodeTypeTag::Form",
157 NodeTypeTag::FieldSet => "NodeTypeTag::FieldSet",
158 NodeTypeTag::Legend => "NodeTypeTag::Legend",
159 NodeTypeTag::Label => "NodeTypeTag::Label",
160 NodeTypeTag::Input => "NodeTypeTag::Input",
161 NodeTypeTag::Button => "NodeTypeTag::Button",
162 NodeTypeTag::Select => "NodeTypeTag::Select",
163 NodeTypeTag::OptGroup => "NodeTypeTag::OptGroup",
164 NodeTypeTag::SelectOption => "NodeTypeTag::SelectOption",
165 NodeTypeTag::TextArea => "NodeTypeTag::TextArea",
166 NodeTypeTag::Output => "NodeTypeTag::Output",
167 NodeTypeTag::Progress => "NodeTypeTag::Progress",
168 NodeTypeTag::Meter => "NodeTypeTag::Meter",
169 NodeTypeTag::DataList => "NodeTypeTag::DataList",
170
171 NodeTypeTag::Span => "NodeTypeTag::Span",
173 NodeTypeTag::A => "NodeTypeTag::A",
174 NodeTypeTag::Em => "NodeTypeTag::Em",
175 NodeTypeTag::Strong => "NodeTypeTag::Strong",
176 NodeTypeTag::B => "NodeTypeTag::B",
177 NodeTypeTag::I => "NodeTypeTag::I",
178 NodeTypeTag::U => "NodeTypeTag::U",
179 NodeTypeTag::S => "NodeTypeTag::S",
180 NodeTypeTag::Mark => "NodeTypeTag::Mark",
181 NodeTypeTag::Del => "NodeTypeTag::Del",
182 NodeTypeTag::Ins => "NodeTypeTag::Ins",
183 NodeTypeTag::Code => "NodeTypeTag::Code",
184 NodeTypeTag::Samp => "NodeTypeTag::Samp",
185 NodeTypeTag::Kbd => "NodeTypeTag::Kbd",
186 NodeTypeTag::Var => "NodeTypeTag::Var",
187 NodeTypeTag::Cite => "NodeTypeTag::Cite",
188 NodeTypeTag::Dfn => "NodeTypeTag::Dfn",
189 NodeTypeTag::Abbr => "NodeTypeTag::Abbr",
190 NodeTypeTag::Acronym => "NodeTypeTag::Acronym",
191 NodeTypeTag::Q => "NodeTypeTag::Q",
192 NodeTypeTag::Time => "NodeTypeTag::Time",
193 NodeTypeTag::Sub => "NodeTypeTag::Sub",
194 NodeTypeTag::Sup => "NodeTypeTag::Sup",
195 NodeTypeTag::Small => "NodeTypeTag::Small",
196 NodeTypeTag::Big => "NodeTypeTag::Big",
197 NodeTypeTag::Bdo => "NodeTypeTag::Bdo",
198 NodeTypeTag::Bdi => "NodeTypeTag::Bdi",
199 NodeTypeTag::Wbr => "NodeTypeTag::Wbr",
200 NodeTypeTag::Ruby => "NodeTypeTag::Ruby",
201 NodeTypeTag::Rt => "NodeTypeTag::Rt",
202 NodeTypeTag::Rtc => "NodeTypeTag::Rtc",
203 NodeTypeTag::Rp => "NodeTypeTag::Rp",
204 NodeTypeTag::Data => "NodeTypeTag::Data",
205
206 NodeTypeTag::Canvas => "NodeTypeTag::Canvas",
208 NodeTypeTag::Object => "NodeTypeTag::Object",
209 NodeTypeTag::Param => "NodeTypeTag::Param",
210 NodeTypeTag::Embed => "NodeTypeTag::Embed",
211 NodeTypeTag::Audio => "NodeTypeTag::Audio",
212 NodeTypeTag::Video => "NodeTypeTag::Video",
213 NodeTypeTag::Source => "NodeTypeTag::Source",
214 NodeTypeTag::Track => "NodeTypeTag::Track",
215 NodeTypeTag::Map => "NodeTypeTag::Map",
216 NodeTypeTag::Area => "NodeTypeTag::Area",
217 NodeTypeTag::Svg => "NodeTypeTag::Svg",
218 NodeTypeTag::SvgPath => "NodeTypeTag::SvgPath",
219 NodeTypeTag::SvgCircle => "NodeTypeTag::SvgCircle",
220 NodeTypeTag::SvgRect => "NodeTypeTag::SvgRect",
221 NodeTypeTag::SvgEllipse => "NodeTypeTag::SvgEllipse",
222 NodeTypeTag::SvgLine => "NodeTypeTag::SvgLine",
223 NodeTypeTag::SvgPolygon => "NodeTypeTag::SvgPolygon",
224 NodeTypeTag::SvgPolyline => "NodeTypeTag::SvgPolyline",
225 NodeTypeTag::SvgG => "NodeTypeTag::SvgG",
226
227 NodeTypeTag::SvgDefs => "NodeTypeTag::SvgDefs",
229 NodeTypeTag::SvgSymbol => "NodeTypeTag::SvgSymbol",
230 NodeTypeTag::SvgUse => "NodeTypeTag::SvgUse",
231 NodeTypeTag::SvgSwitch => "NodeTypeTag::SvgSwitch",
232
233 NodeTypeTag::SvgText => "NodeTypeTag::SvgText",
235 NodeTypeTag::SvgTspan => "NodeTypeTag::SvgTspan",
236 NodeTypeTag::SvgTextPath => "NodeTypeTag::SvgTextPath",
237
238 NodeTypeTag::SvgLinearGradient => "NodeTypeTag::SvgLinearGradient",
240 NodeTypeTag::SvgRadialGradient => "NodeTypeTag::SvgRadialGradient",
241 NodeTypeTag::SvgStop => "NodeTypeTag::SvgStop",
242 NodeTypeTag::SvgPattern => "NodeTypeTag::SvgPattern",
243
244 NodeTypeTag::SvgClipPathElement => "NodeTypeTag::SvgClipPathElement",
246 NodeTypeTag::SvgMask => "NodeTypeTag::SvgMask",
247
248 NodeTypeTag::SvgFilter => "NodeTypeTag::SvgFilter",
250 NodeTypeTag::SvgFeBlend => "NodeTypeTag::SvgFeBlend",
251 NodeTypeTag::SvgFeColorMatrix => "NodeTypeTag::SvgFeColorMatrix",
252 NodeTypeTag::SvgFeComponentTransfer => "NodeTypeTag::SvgFeComponentTransfer",
253 NodeTypeTag::SvgFeComposite => "NodeTypeTag::SvgFeComposite",
254 NodeTypeTag::SvgFeConvolveMatrix => "NodeTypeTag::SvgFeConvolveMatrix",
255 NodeTypeTag::SvgFeDiffuseLighting => "NodeTypeTag::SvgFeDiffuseLighting",
256 NodeTypeTag::SvgFeDisplacementMap => "NodeTypeTag::SvgFeDisplacementMap",
257 NodeTypeTag::SvgFeDistantLight => "NodeTypeTag::SvgFeDistantLight",
258 NodeTypeTag::SvgFeDropShadow => "NodeTypeTag::SvgFeDropShadow",
259 NodeTypeTag::SvgFeFlood => "NodeTypeTag::SvgFeFlood",
260 NodeTypeTag::SvgFeFuncR => "NodeTypeTag::SvgFeFuncR",
261 NodeTypeTag::SvgFeFuncG => "NodeTypeTag::SvgFeFuncG",
262 NodeTypeTag::SvgFeFuncB => "NodeTypeTag::SvgFeFuncB",
263 NodeTypeTag::SvgFeFuncA => "NodeTypeTag::SvgFeFuncA",
264 NodeTypeTag::SvgFeGaussianBlur => "NodeTypeTag::SvgFeGaussianBlur",
265 NodeTypeTag::SvgFeImage => "NodeTypeTag::SvgFeImage",
266 NodeTypeTag::SvgFeMerge => "NodeTypeTag::SvgFeMerge",
267 NodeTypeTag::SvgFeMergeNode => "NodeTypeTag::SvgFeMergeNode",
268 NodeTypeTag::SvgFeMorphology => "NodeTypeTag::SvgFeMorphology",
269 NodeTypeTag::SvgFeOffset => "NodeTypeTag::SvgFeOffset",
270 NodeTypeTag::SvgFePointLight => "NodeTypeTag::SvgFePointLight",
271 NodeTypeTag::SvgFeSpecularLighting => "NodeTypeTag::SvgFeSpecularLighting",
272 NodeTypeTag::SvgFeSpotLight => "NodeTypeTag::SvgFeSpotLight",
273 NodeTypeTag::SvgFeTile => "NodeTypeTag::SvgFeTile",
274 NodeTypeTag::SvgFeTurbulence => "NodeTypeTag::SvgFeTurbulence",
275
276 NodeTypeTag::SvgMarker => "NodeTypeTag::SvgMarker",
278 NodeTypeTag::SvgImage => "NodeTypeTag::SvgImage",
279 NodeTypeTag::SvgForeignObject => "NodeTypeTag::SvgForeignObject",
280
281 NodeTypeTag::SvgTitle => "NodeTypeTag::SvgTitle",
283 NodeTypeTag::SvgDesc => "NodeTypeTag::SvgDesc",
284 NodeTypeTag::SvgMetadata => "NodeTypeTag::SvgMetadata",
285 NodeTypeTag::SvgA => "NodeTypeTag::SvgA",
286 NodeTypeTag::SvgView => "NodeTypeTag::SvgView",
287 NodeTypeTag::SvgStyle => "NodeTypeTag::SvgStyle",
288 NodeTypeTag::SvgScript => "NodeTypeTag::SvgScript",
289
290 NodeTypeTag::SvgAnimate => "NodeTypeTag::SvgAnimate",
292 NodeTypeTag::SvgAnimateMotion => "NodeTypeTag::SvgAnimateMotion",
293 NodeTypeTag::SvgAnimateTransform => "NodeTypeTag::SvgAnimateTransform",
294 NodeTypeTag::SvgSet => "NodeTypeTag::SvgSet",
295 NodeTypeTag::SvgMpath => "NodeTypeTag::SvgMpath",
296
297 NodeTypeTag::Title => "NodeTypeTag::Title",
299 NodeTypeTag::Meta => "NodeTypeTag::Meta",
300 NodeTypeTag::Link => "NodeTypeTag::Link",
301 NodeTypeTag::Script => "NodeTypeTag::Script",
302 NodeTypeTag::Style => "NodeTypeTag::Style",
303 NodeTypeTag::Base => "NodeTypeTag::Base",
304
305 NodeTypeTag::Text => "NodeTypeTag::Text",
307 NodeTypeTag::Img => "NodeTypeTag::Img",
308 NodeTypeTag::VirtualView => "NodeTypeTag::VirtualView",
309 NodeTypeTag::Icon => "NodeTypeTag::Icon",
310 NodeTypeTag::GeolocationProbe => "NodeTypeTag::GeolocationProbe",
311
312 NodeTypeTag::Before => "NodeTypeTag::Before",
314 NodeTypeTag::After => "NodeTypeTag::After",
315 NodeTypeTag::Marker => "NodeTypeTag::Marker",
316 NodeTypeTag::Placeholder => "NodeTypeTag::Placeholder",
317 }
318}
319
320pub fn print_block_path(path: &CssPath, tabs: usize) -> String {
321 let t = String::from(" ").repeat(tabs);
322 let t1 = String::from(" ").repeat(tabs + 1);
323
324 format!(
325 "CssPath {{\r\n{}selectors: {}\r\n{}}}",
326 t1,
327 format_selectors(path.selectors.as_ref(), tabs + 1),
328 t
329 )
330}
331
332pub fn format_selectors(selectors: &[CssPathSelector], tabs: usize) -> String {
333 let t = String::from(" ").repeat(tabs);
334 let t1 = String::from(" ").repeat(tabs + 1);
335
336 let selectors_formatted = selectors
337 .iter()
338 .map(|s| format!("{}{},", t1, format_single_selector(s, tabs + 1)))
339 .collect::<Vec<String>>()
340 .join("\r\n");
341
342 format!("vec![\r\n{}\r\n{}].into()", selectors_formatted, t)
343}
344
345pub fn format_single_selector(p: &CssPathSelector, _tabs: usize) -> String {
346 match p {
347 CssPathSelector::Global => "CssPathSelector::Global".to_string(),
348 CssPathSelector::Type(ntp) => format!("CssPathSelector::Type({})", format_node_type(ntp)),
349 CssPathSelector::Class(class) => {
350 format!("CssPathSelector::Class(String::from({:?}))", class)
351 }
352 CssPathSelector::Id(id) => format!("CssPathSelector::Id(String::from({:?}))", id),
353 CssPathSelector::PseudoSelector(cps) => format!(
354 "CssPathSelector::PseudoSelector({})",
355 format_pseudo_selector_type(cps)
356 ),
357 CssPathSelector::Attribute(a) => format!(
358 "CssPathSelector::Attribute({})",
359 format_attribute_selector(a)
360 ),
361 CssPathSelector::DirectChildren => "CssPathSelector::DirectChildren".to_string(),
362 CssPathSelector::Children => "CssPathSelector::Children".to_string(),
363 CssPathSelector::AdjacentSibling => "CssPathSelector::AdjacentSibling".to_string(),
364 CssPathSelector::GeneralSibling => "CssPathSelector::GeneralSibling".to_string(),
365 }
366}
367
368pub fn format_pseudo_selector_type(p: &CssPathPseudoSelector) -> String {
369 match p {
370 CssPathPseudoSelector::First => "CssPathPseudoSelector::First".to_string(),
371 CssPathPseudoSelector::Last => "CssPathPseudoSelector::Last".to_string(),
372 CssPathPseudoSelector::NthChild(n) => format!(
373 "CssPathPseudoSelector::NthChild({})",
374 format_nth_child_selector(n)
375 ),
376 CssPathPseudoSelector::Hover => "CssPathPseudoSelector::Hover".to_string(),
377 CssPathPseudoSelector::Active => "CssPathPseudoSelector::Active".to_string(),
378 CssPathPseudoSelector::Focus => "CssPathPseudoSelector::Focus".to_string(),
379 CssPathPseudoSelector::Backdrop => "CssPathPseudoSelector::Backdrop".to_string(),
380 CssPathPseudoSelector::Lang(lang) => format!(
381 "CssPathPseudoSelector::Lang(AzString::from_const_str(\"{}\"))",
382 lang.as_str()
383 ),
384 CssPathPseudoSelector::Dragging => "CssPathPseudoSelector::Dragging".to_string(),
385 CssPathPseudoSelector::DragOver => "CssPathPseudoSelector::DragOver".to_string(),
386 }
387}
388
389pub fn format_attribute_selector(a: &CssAttributeSelector) -> String {
390 let value = match a.value.as_ref() {
391 Some(v) => format!(
392 "OptionString::Some(AzString::from_const_str({:?}))",
393 v.as_str()
394 ),
395 None => "OptionString::None".to_string(),
396 };
397 format!(
398 "CssAttributeSelector {{ name: AzString::from_const_str({:?}), op: {}, value: {} }}",
399 a.name.as_str(),
400 format_attribute_match_op(&a.op),
401 value
402 )
403}
404
405pub fn format_attribute_match_op(op: &AttributeMatchOp) -> String {
406 match op {
407 AttributeMatchOp::Exists => "AttributeMatchOp::Exists".to_string(),
408 AttributeMatchOp::Eq => "AttributeMatchOp::Eq".to_string(),
409 AttributeMatchOp::Includes => "AttributeMatchOp::Includes".to_string(),
410 AttributeMatchOp::DashMatch => "AttributeMatchOp::DashMatch".to_string(),
411 AttributeMatchOp::Prefix => "AttributeMatchOp::Prefix".to_string(),
412 AttributeMatchOp::Suffix => "AttributeMatchOp::Suffix".to_string(),
413 AttributeMatchOp::Substring => "AttributeMatchOp::Substring".to_string(),
414 }
415}
416
417pub fn format_nth_child_selector(n: &CssNthChildSelector) -> String {
418 match n {
419 CssNthChildSelector::Number(num) => format!("CssNthChildSelector::Number({})", num),
420 CssNthChildSelector::Even => "CssNthChildSelector::Even".to_string(),
421 CssNthChildSelector::Odd => "CssNthChildSelector::Odd".to_string(),
422 CssNthChildSelector::Pattern(CssNthChildPattern {
423 pattern_repeat,
424 offset,
425 }) => format!(
426 "CssNthChildSelector::Pattern(CssNthChildPattern {{ pattern_repeat: {}, offset: {} }})",
427 pattern_repeat, offset
428 ),
429 }
430}
431
432pub fn print_declaration(decl: &CssDeclaration, tabs: usize) -> String {
433 match decl {
434 CssDeclaration::Static(s) => format!(
435 "CssDeclaration::Static({})",
436 format_static_css_prop(s, tabs)
437 ),
438 CssDeclaration::Dynamic(d) => format!(
439 "CssDeclaration::Dynamic({})",
440 format_dynamic_css_prop(d, tabs)
441 ),
442 }
443}
444
445pub fn format_dynamic_css_prop(decl: &DynamicCssProperty, tabs: usize) -> String {
446 let t = String::from(" ").repeat(tabs);
447 format!(
448 "DynamicCssProperty {{\r\n{} dynamic_id: {:?},\r\n{} default_value: {},\r\n{}}}",
449 t,
450 decl.dynamic_id,
451 t,
452 format_static_css_prop(&decl.default_value, tabs + 1),
453 t
454 )
455}
456
457#[cfg(test)]
458mod tests {
459 use alloc::vec;
460
461 use super::*;
462 use crate::css::CssRuleBlock;
463
464 fn sample_css() -> Css {
465 let path = CssPath::new(vec![CssPathSelector::Type(NodeTypeTag::Div)]);
466 let block = CssRuleBlock::new(path, vec![]);
467 Css {
468 rules: vec![block].into(),
469 }
470 }
471
472 #[test]
473 fn rust_backend_emits_const_literal() {
474 let css = sample_css();
475 let rust = RustBackend.emit_css(&css);
476 assert!(rust.contains("const CSS: Css"));
477 assert!(rust.contains("NodeTypeTag::Div"));
478 }
479
480 #[test]
481 fn rust_backend_emits_project_files() {
482 let css = sample_css();
483 let files = RustBackend.emit_project(&css);
484 let paths: alloc::vec::Vec<_> = files.iter().map(|f| f.path.as_str()).collect();
485 assert!(paths.contains(&"Cargo.toml"));
486 assert!(paths.contains(&"src/main.rs"));
487 let main_rs = files
488 .iter()
489 .find(|f| f.path == "src/main.rs")
490 .expect("main.rs missing");
491 assert!(main_rs.contains_const_literal());
492 }
493
494 impl GeneratedFile {
495 fn contains_const_literal(&self) -> bool {
496 self.contents.contains("const CSS: Css")
497 }
498 }
499}