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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
pub trait Minify
{
#[doc(hidden)]
const PRESERVE_COMMENTS: bool = false;
#[doc(hidden)]
const PRESERVE_PROCESSING_INSTRUCTIONS: bool = false;
#[doc(hidden)]
const COLLAPSE_WHITESPACE: bool = true;
#[inline(always)]
fn debug_fmt<W: fmt::Write>(&self, f: &mut W) -> fmt::Result;
#[inline(always)]
fn debug_string(&self) -> String
{
let mut debug = String::new();
self.debug_fmt(&mut debug).unwrap();
debug
}
#[inline(always)]
fn minify_to_file_path<P: AsRef<Path>>(&self, html_head_and_body_tags_are_optional: bool, html_file_path: P) -> Result<(), HtmlError>
{
use ::std::fs::File;
let path = html_file_path.as_ref();
let file = File::create(path).context(path)?;
self.minify_to_writer(html_head_and_body_tags_are_optional, file).context(path)?;
Ok(())
}
#[inline(always)]
fn minify_to_string(&self, html_head_and_body_tags_are_optional: bool) -> String
{
let bytes = self.minify_to_bytes(html_head_and_body_tags_are_optional);
String::from_utf8(bytes).unwrap()
}
#[inline(always)]
fn minify_to_bytes(&self, html_head_and_body_tags_are_optional: bool) -> Vec<u8>
{
let mut bytes = Vec::new();
self.minify_to_writer(html_head_and_body_tags_are_optional, &mut bytes).unwrap();
bytes
}
#[inline(always)]
fn minify_to_writer<W: Write>(&self, html_head_and_body_tags_are_optional: bool, writer: W) -> io::Result<()>;
#[doc(hidden)]
#[inline(always)]
fn _serializer<W: Write>(html_head_and_body_tags_are_optional: bool, writer: W) -> UltraMinifyingHtmlSerializer<W>
{
UltraMinifyingHtmlSerializer::new(html_head_and_body_tags_are_optional, Self::PRESERVE_COMMENTS, Self::PRESERVE_PROCESSING_INSTRUCTIONS, writer)
}
}
impl Minify for RcDom
{
#[inline(always)]
fn debug_fmt<W: fmt::Write>(&self, f: &mut W) -> fmt::Result
{
self.document.debug_fmt(f)
}
#[inline(always)]
fn minify_to_writer<W: Write>(&self, html_head_and_body_tags_are_optional: bool, writer: W) -> io::Result<()>
{
self.document.minify_to_writer(html_head_and_body_tags_are_optional, writer)
}
}
impl Minify for Rc<Node>
{
#[inline(always)]
fn debug_fmt<W: fmt::Write>(&self, f: &mut W) -> fmt::Result
{
write!(f, "{}", self.minify_to_string(true))
}
#[inline(always)]
fn minify_to_writer<W: Write>(&self, html_head_and_body_tags_are_optional: bool, writer: W) -> io::Result<()>
{
Self::_serializer(html_head_and_body_tags_are_optional, writer).serialize_node(self, Self::COLLAPSE_WHITESPACE, true)
}
}
impl Minify for RefCell<Vec<Rc<Node>>>
{
#[inline(always)]
fn debug_fmt<W: fmt::Write>(&self, f: &mut W) -> fmt::Result
{
for node in self.borrow().iter()
{
node.debug_fmt(f)?;
}
Ok(())
}
#[inline(always)]
fn minify_to_writer<W: Write>(&self, html_head_and_body_tags_are_optional: bool, mut writer: W) -> io::Result<()>
{
{
let mut serializer = Self::_serializer(html_head_and_body_tags_are_optional, &mut writer);
for node in self.borrow().iter()
{
serializer.serialize_node(node, Self::COLLAPSE_WHITESPACE, false)?;
}
}
writer.flush()
}
}