Skip to content

Commit 5ff219a

Browse files
committed
re-rustfmt all code
rustfmt 1.4.13-nightly (c126730 2020-03-31)
1 parent 17c1a14 commit 5ff219a

7 files changed

Lines changed: 111 additions & 146 deletions

File tree

marked/benches/round_trip.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use html5ever::serialize as rc_serialize;
1515
use markup5ever_rcdom::{RcDom, SerializableHandle};
1616

1717
use marked;
18-
use marked::{Decoder, Document, EncodingHint};
1918
use marked::chain_filters;
2019
use marked::filter;
2120
use marked::html::parse_buffered;
21+
use marked::{Decoder, Document, EncodingHint};
2222
use marked::{Decoder, EncodingHint};
2323

2424
#[bench]
@@ -134,8 +134,7 @@ fn b31_text_normalize_content_identity(b: &mut Bencher) {
134134

135135
#[bench]
136136
fn b50_sparse_bulk_clone(b: &mut Bencher) {
137-
let mut fin = sample_file("github-dekellum.html")
138-
.expect("sample_file");
137+
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
139138
let eh = EncodingHint::shared_default(enc::UTF_8);
140139
let mut doc = parse_buffered(eh, &mut fin).expect("parse");
141140
filter_all(&mut doc);
@@ -147,8 +146,7 @@ fn b50_sparse_bulk_clone(b: &mut Bencher) {
147146

148147
#[bench]
149148
fn b51_sparse_compact(b: &mut Bencher) {
150-
let mut fin = sample_file("github-dekellum.html")
151-
.expect("sample_file");
149+
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
152150
let eh = EncodingHint::shared_default(enc::UTF_8);
153151
let mut doc = parse_buffered(eh, &mut fin).expect("parse");
154152
filter_all(&mut doc);
@@ -161,8 +159,7 @@ fn b51_sparse_compact(b: &mut Bencher) {
161159

162160
#[bench]
163161
fn b52_sparse_deep_clone(b: &mut Bencher) {
164-
let mut fin = sample_file("github-dekellum.html")
165-
.expect("sample_file");
162+
let mut fin = sample_file("github-dekellum.html").expect("sample_file");
166163
let eh = EncodingHint::shared_default(enc::UTF_8);
167164
let mut doc = parse_buffered(eh, &mut fin).expect("parse");
168165
filter_all(&mut doc);

marked/src/dom.rs

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,22 @@ pub enum NodeData {
101101
#[derive(Clone, Debug)]
102102
pub struct DocumentType {
103103
pub name: StrTendril,
104-
_priv: ()
104+
_priv: (),
105105
}
106106

107107
/// Processing instruction details.
108108
#[derive(Clone, Debug)]
109109
pub struct ProcessingInstruction {
110110
pub data: StrTendril,
111-
_priv: ()
111+
_priv: (),
112112
}
113113

114114
/// A markup element with name and attributes.
115115
#[derive(Clone, Debug)]
116116
pub struct Element {
117117
pub name: QualName,
118118
pub attrs: Vec<Attribute>,
119-
_priv: ()
119+
_priv: (),
120120
}
121121

122122
/// Core implementation.
@@ -133,8 +133,8 @@ impl Document {
133133
/// specified capacity.
134134
pub fn with_capacity(count: u32) -> Self {
135135
let mut nodes = Vec::with_capacity(count as usize);
136-
nodes.push(Node::new(NodeData::Hole)); // Index 0: Padding
137-
nodes.push(Node::new(NodeData::Document)); // Index 1: DOCUMENT_NODE_ID
136+
nodes.push(Node::new(NodeData::Hole)); // Index 0: Padding
137+
nodes.push(Node::new(NodeData::Document)); // Index 1: DOCUMENT_NODE_ID
138138
Document { nodes }
139139
}
140140

@@ -164,18 +164,21 @@ impl Document {
164164
pub fn root_element(&self) -> Option<NodeId> {
165165
let document_node = &self[Document::DOCUMENT_NODE_ID];
166166
debug_assert!(
167-
(if let NodeData::Document = document_node.data { true }
168-
else { false }),
169-
"not document node: {:?}", document_node);
167+
(if let NodeData::Document = document_node.data {
168+
true
169+
} else {
170+
false
171+
}),
172+
"not document node: {:?}",
173+
document_node
174+
);
170175
debug_assert!(document_node.parent.is_none());
171176
debug_assert!(document_node.next_sibling.is_none());
172177
debug_assert!(document_node.prev_sibling.is_none());
173178
let mut root = None;
174179
for child in self.children(Document::DOCUMENT_NODE_ID) {
175180
match &self[child].data {
176-
NodeData::DocType(_) |
177-
NodeData::Comment(_) |
178-
NodeData::Pi(_) => {}
181+
NodeData::DocType(_) | NodeData::Comment(_) | NodeData::Pi(_) => {}
179182
NodeData::Document => {
180183
debug_assert!(false, "Document child of Document");
181184
root = None;
@@ -205,10 +208,17 @@ impl Document {
205208

206209
fn push_node(&mut self, node: Node) -> NodeId {
207210
debug_assert!(
208-
(if let NodeData::Document | NodeData::Hole = node.data { false }
209-
else { true }),
210-
"Invalid push {:?}", node.data);
211-
let next_index = self.nodes.len()
211+
(if let NodeData::Document | NodeData::Hole = node.data {
212+
false
213+
} else {
214+
true
215+
}),
216+
"Invalid push {:?}",
217+
node.data
218+
);
219+
let next_index = self
220+
.nodes
221+
.len()
212222
.try_into()
213223
.expect("Document (u32) node index overflow");
214224
debug_assert!(next_index > 1);
@@ -283,7 +293,8 @@ impl Document {
283293

284294
fn insert_before(&mut self, sibling: NodeId, new_sibling: NodeId) {
285295
self.detach(new_sibling);
286-
let parent = self[sibling].parent
296+
let parent = self[sibling]
297+
.parent
287298
.expect("insert_before sibling has parent");
288299
self[parent].assert_suitable_parent();
289300
self[new_sibling].parent = Some(parent);
@@ -370,7 +381,8 @@ impl Document {
370381
push_if_pair(
371382
&mut next,
372383
self[Document::DOCUMENT_NODE_ID].first_child,
373-
Document::DOCUMENT_NODE_ID);
384+
Document::DOCUMENT_NODE_ID,
385+
);
374386

375387
while let Some((id, nid)) = next.pop() {
376388
let data = mem::replace(&mut self[id].data, NodeData::Hole);
@@ -414,7 +426,9 @@ impl Document {
414426
/// same as the original. As compared with `deep_clone(DOCUMENT_NODE_ID)`
415427
/// this is faster but potentially much less memory efficient.
416428
pub fn bulk_clone(&self) -> Document {
417-
Document { nodes: self.nodes.clone() }
429+
Document {
430+
nodes: self.nodes.clone(),
431+
}
418432
}
419433

420434
/// Replace the specified node ID with its children.
@@ -481,7 +495,7 @@ impl Element {
481495
Element {
482496
name: QualName::new(None, ns!(), lname.into()),
483497
attrs: Vec::new(),
484-
_priv: ()
498+
_priv: (),
485499
}
486500
}
487501

@@ -688,9 +702,14 @@ impl NodeData {
688702
#[inline]
689703
fn assert_suitable_parent(&self) {
690704
debug_assert!(
691-
(if let NodeData::Document | NodeData::Elem(_) = self { true }
692-
else { false }),
693-
"Not a suitable parent: {:?}", self)
705+
(if let NodeData::Document | NodeData::Elem(_) = self {
706+
true
707+
} else {
708+
false
709+
}),
710+
"Not a suitable parent: {:?}",
711+
self
712+
)
694713
}
695714
}
696715

@@ -700,11 +719,7 @@ fn push_if(stack: &mut Vec<NodeId>, id: Option<NodeId>) {
700719
}
701720
}
702721

703-
fn push_if_pair(
704-
stack: &mut Vec<(NodeId, NodeId)>,
705-
id: Option<NodeId>,
706-
oid: NodeId)
707-
{
722+
fn push_if_pair(stack: &mut Vec<(NodeId, NodeId)>, id: Option<NodeId>, oid: NodeId) {
708723
if let Some(id) = id {
709724
stack.push((id, oid));
710725
}

marked/src/dom/html.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ use log::{debug, info, trace};
2323
use tendril::{fmt as form, Tendril};
2424

2525
use crate::{
26-
Attribute, Decoder, Document, DocumentType, Element, EncodingHint,
27-
Node, NodeData, NodeId, ProcessingInstruction, SharedEncodingHint,
28-
BOM_CONF, HTML_META_CONF, INITIAL_BUFFER_SIZE,
26+
Attribute, Decoder, Document, DocumentType, Element, EncodingHint, Node, NodeData, NodeId,
27+
ProcessingInstruction, SharedEncodingHint, BOM_CONF, HTML_META_CONF, INITIAL_BUFFER_SIZE,
2928
};
3029

3130
mod meta;
@@ -365,19 +364,20 @@ impl TreeSink for Sink {
365364
&mut self,
366365
name: QualName,
367366
attrs: Vec<Attribute>,
368-
_flags: ElementFlags)
369-
-> NodeId
370-
{
371-
self.new_node(NodeData::Elem(Element { name, attrs, _priv: () }))
367+
_flags: ElementFlags,
368+
) -> NodeId {
369+
self.new_node(NodeData::Elem(Element {
370+
name,
371+
attrs,
372+
_priv: (),
373+
}))
372374
}
373375

374376
fn create_comment(&mut self, text: StrTendril) -> NodeId {
375377
self.new_node(NodeData::Comment(text))
376378
}
377379

378-
fn create_pi(&mut self, _target: StrTendril, data: StrTendril)
379-
-> NodeId
380-
{
380+
fn create_pi(&mut self, _target: StrTendril, data: StrTendril) -> NodeId {
381381
self.new_node(NodeData::Pi(ProcessingInstruction { data, _priv: () }))
382382
}
383383

@@ -414,19 +414,13 @@ impl TreeSink for Sink {
414414
&mut self,
415415
name: StrTendril,
416416
_p_id: StrTendril,
417-
_s_id: StrTendril)
418-
{
419-
let node = self.new_node(NodeData::DocType(
420-
DocumentType { name, _priv: () }
421-
));
417+
_s_id: StrTendril,
418+
) {
419+
let node = self.new_node(NodeData::DocType(DocumentType { name, _priv: () }));
422420
self.document.append(Document::DOCUMENT_NODE_ID, node)
423421
}
424422

425-
fn add_attrs_if_missing(
426-
&mut self,
427-
&target: &NodeId,
428-
attrs: Vec<Attribute>)
429-
{
423+
fn add_attrs_if_missing(&mut self, &target: &NodeId, attrs: Vec<Attribute>) {
430424
// Note this is only used in few, strange cases involving re-working of
431425
// html and body node attributes, but it definitely needs to be
432426
// implemented.

marked/src/dom/serializer.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a> Serialize for NodeRef<'a> {
3636
if *scope == IncludeNode {
3737
serializer.start_elem(
3838
elm.name.clone(),
39-
elm.attrs.iter().map(|a| (&a.name, a.value.as_ref()))
39+
elm.attrs.iter().map(|a| (&a.name, a.value.as_ref())),
4040
)?;
4141
}
4242
for child in self.children() {
@@ -49,9 +49,7 @@ impl<'a> Serialize for NodeRef<'a> {
4949
Ok(())
5050
}
5151

52-
(_, Hole) => {
53-
panic!("Hole in Document")
54-
}
52+
(_, Hole) => panic!("Hole in Document"),
5553

5654
(_, Document) => {
5755
for child in self.children() {
@@ -62,18 +60,10 @@ impl<'a> Serialize for NodeRef<'a> {
6260

6361
(ChildrenOnly(_), _) => Ok(()),
6462

65-
(IncludeNode, DocType(ref dt)) => {
66-
serializer.write_doctype(&dt.name)
67-
}
68-
(IncludeNode, Text(ref t)) => {
69-
serializer.write_text(&t)
70-
}
71-
(IncludeNode, Comment(ref t)) => {
72-
serializer.write_comment(&t)
73-
}
74-
(IncludeNode, Pi(ref pi)) => {
75-
serializer.write_processing_instruction(&"", &pi.data)
76-
}
63+
(IncludeNode, DocType(ref dt)) => serializer.write_doctype(&dt.name),
64+
(IncludeNode, Text(ref t)) => serializer.write_text(&t),
65+
(IncludeNode, Comment(ref t)) => serializer.write_comment(&t),
66+
(IncludeNode, Pi(ref pi)) => serializer.write_processing_instruction(&"", &pi.data),
7767
}
7868
}
7969
}

0 commit comments

Comments
 (0)