1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
pub trait HasCssRulesExt: HasCssRules
{
fn remove_unused_css_rules<HtmlDocumentOrNode: Selectable>(&mut self, html_document_and_nodes: &[&HtmlDocumentOrNode]) -> bool;
}
impl<H: HasCssRules> HasCssRulesExt for H
{
fn remove_unused_css_rules<HtmlDocumentOrNode: Selectable>(&mut self, html_document_and_nodes: &[&HtmlDocumentOrNode]) -> bool
{
let css_rules = self.css_rules_vec_mut();
css_rules.retain_mut(|css_rule|
{
match *css_rule
{
CssRule::Style(ref mut style_rule) =>
{
style_rule.selectors.remove_unmatched_selectors(html_document_and_nodes);
!style_rule.selectors.0.is_empty()
}
CssRule::Document(ref mut document_at_rule) => document_at_rule.remove_unused_css_rules(html_document_and_nodes),
CssRule::Media(ref mut media_at_rule) => media_at_rule.remove_unused_css_rules(html_document_and_nodes),
CssRule::Supports(ref mut supports_at_rule) => supports_at_rule.remove_unused_css_rules(html_document_and_nodes),
_ => true,
}
});
!css_rules.is_empty()
}
}