Skip to content

Commit bcd3819

Browse files
committed
fix formatting
1 parent afe265b commit bcd3819

10 files changed

Lines changed: 161 additions & 233 deletions

File tree

.rustfmt.toml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
max_width = 120
22
use_small_heuristics = "Max"
3-
empty_item_single_line = false
4-
force_multiline_blocks = true
5-
format_code_in_doc_comments = true
63
match_block_trailing_comma = true
7-
imports_granularity = "Crate"
8-
normalize_comments = true
9-
normalize_doc_attributes = true
10-
overflow_delimited_expr = true
11-
reorder_impl_items = true
124
reorder_imports = true
13-
group_imports = "StdExternalCrate"
145
tab_spaces = 2
156
use_field_init_shorthand = true
167
use_try_shorthand = true

src/app.rs

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,24 @@ impl App {
9494
.popup
9595
.as_mut()
9696
.and_then(|pane| pane.handle_events(e.clone(), &mut self.state).ok())
97-
.map(|response| {
98-
match response {
97+
.map(|response| match response {
98+
Some(tui::EventResponse::Continue(action)) => {
99+
action_tx.send(action).ok();
100+
false
101+
},
102+
Some(tui::EventResponse::Stop(action)) => {
103+
action_tx.send(action).ok();
104+
true
105+
},
106+
_ => false,
107+
})
108+
.unwrap_or(false);
109+
stop_event_propagation = stop_event_propagation
110+
|| self
111+
.pages
112+
.get_mut(self.active_page)
113+
.and_then(|page| page.handle_events(e.clone(), &mut self.state).ok())
114+
.map(|response| match response {
99115
Some(tui::EventResponse::Continue(action)) => {
100116
action_tx.send(action).ok();
101117
false
@@ -105,45 +121,23 @@ impl App {
105121
true
106122
},
107123
_ => false,
108-
}
109-
})
110-
.unwrap_or(false);
111-
stop_event_propagation = stop_event_propagation
112-
|| self
113-
.pages
114-
.get_mut(self.active_page)
115-
.and_then(|page| page.handle_events(e.clone(), &mut self.state).ok())
116-
.map(|response| {
117-
match response {
118-
Some(tui::EventResponse::Continue(action)) => {
119-
action_tx.send(action).ok();
120-
false
121-
},
122-
Some(tui::EventResponse::Stop(action)) => {
123-
action_tx.send(action).ok();
124-
true
125-
},
126-
_ => false,
127-
}
128124
})
129125
.unwrap_or(false);
130126

131127
stop_event_propagation = stop_event_propagation
132128
|| self
133129
.footer
134130
.handle_events(e.clone(), &mut self.state)
135-
.map(|response| {
136-
match response {
137-
Some(tui::EventResponse::Continue(action)) => {
138-
action_tx.send(action).ok();
139-
false
140-
},
141-
Some(tui::EventResponse::Stop(action)) => {
142-
action_tx.send(action).ok();
143-
true
144-
},
145-
_ => false,
146-
}
131+
.map(|response| match response {
132+
Some(tui::EventResponse::Continue(action)) => {
133+
action_tx.send(action).ok();
134+
false
135+
},
136+
Some(tui::EventResponse::Stop(action)) => {
137+
action_tx.send(action).ok();
138+
true
139+
},
140+
_ => false,
147141
})
148142
.unwrap_or(false);
149143

src/components/schema_viewer.rs

Lines changed: 64 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,16 @@ fn to_node(
221221
}
222222
Node::Object(pairs)
223223
},
224-
serde_json::Value::Array(items) => {
225-
Node::Array(
226-
items
227-
.iter()
228-
.enumerate()
229-
.map(|(i, v)| {
230-
let child_path = format!("{parent_path}/{i}");
231-
to_node(v, &child_path, components, variant_selection, expanding)
232-
})
233-
.collect(),
234-
)
235-
},
224+
serde_json::Value::Array(items) => Node::Array(
225+
items
226+
.iter()
227+
.enumerate()
228+
.map(|(i, v)| {
229+
let child_path = format!("{parent_path}/{i}");
230+
to_node(v, &child_path, components, variant_selection, expanding)
231+
})
232+
.collect(),
233+
),
236234
_ => Node::Scalar(value.clone()),
237235
}
238236
}
@@ -244,11 +242,9 @@ fn all_of_members(value: &serde_json::Value) -> Option<&Vec<serde_json::Value>>
244242
fn all_of_sources(members: &[serde_json::Value]) -> String {
245243
members
246244
.iter()
247-
.map(|m| {
248-
match ref_target_name(m) {
249-
Some(name) => name.to_string(),
250-
None => "<inline>".to_string(),
251-
}
245+
.map(|m| match ref_target_name(m) {
246+
Some(name) => name.to_string(),
247+
None => "<inline>".to_string(),
252248
})
253249
.collect::<Vec<_>>()
254250
.join(", ")
@@ -735,11 +731,9 @@ fn type_str_or_array(pairs: &[(String, Node)], key: &str) -> Option<String> {
735731
Node::Array(items) => {
736732
let parts: Vec<String> = items
737733
.iter()
738-
.filter_map(|item| {
739-
match item {
740-
Node::Scalar(serde_json::Value::String(s)) if s != "null" => Some(s.clone()),
741-
_ => None,
742-
}
734+
.filter_map(|item| match item {
735+
Node::Scalar(serde_json::Value::String(s)) if s != "null" => Some(s.clone()),
736+
_ => None,
743737
})
744738
.collect();
745739
if parts.is_empty() {
@@ -1339,11 +1333,9 @@ mod tests {
13391333

13401334
let yaml = blocks
13411335
.iter()
1342-
.filter_map(|b| {
1343-
match b {
1344-
RenderBlock::Yaml(s) => Some(s.as_str()),
1345-
_ => None,
1346-
}
1336+
.filter_map(|b| match b {
1337+
RenderBlock::Yaml(s) => Some(s.as_str()),
1338+
_ => None,
13471339
})
13481340
.collect::<String>();
13491341

@@ -1368,11 +1360,9 @@ mod tests {
13681360

13691361
let variants = blocks
13701362
.iter()
1371-
.find_map(|b| {
1372-
match b {
1373-
RenderBlock::Variants { choices, selected, body_blocks, .. } => Some((choices, *selected, body_blocks)),
1374-
_ => None,
1375-
}
1363+
.find_map(|b| match b {
1364+
RenderBlock::Variants { choices, selected, body_blocks, .. } => Some((choices, *selected, body_blocks)),
1365+
_ => None,
13761366
})
13771367
.expect("expected a Variants block");
13781368

@@ -1382,11 +1372,9 @@ mod tests {
13821372
let body_yaml: String = variants
13831373
.2
13841374
.iter()
1385-
.filter_map(|b| {
1386-
match b {
1387-
RenderBlock::Yaml(s) => Some(s.as_str()),
1388-
_ => None,
1389-
}
1375+
.filter_map(|b| match b {
1376+
RenderBlock::Yaml(s) => Some(s.as_str()),
1377+
_ => None,
13901378
})
13911379
.collect();
13921380
assert!(body_yaml.contains("x-tag: a"), "body did not have selected variant: {body_yaml}");
@@ -1417,11 +1405,9 @@ mod tests {
14171405
let after_yaml: String = blocks
14181406
.iter()
14191407
.skip(marker_idx + 1)
1420-
.filter_map(|b| {
1421-
match b {
1422-
RenderBlock::Yaml(s) => Some(s.as_str()),
1423-
_ => None,
1424-
}
1408+
.filter_map(|b| match b {
1409+
RenderBlock::Yaml(s) => Some(s.as_str()),
1410+
_ => None,
14251411
})
14261412
.collect();
14271413
assert!(after_yaml.contains("name:"), "merged yaml missing 'name': {after_yaml}");
@@ -1501,22 +1487,18 @@ mod tests {
15011487

15021488
let v = blocks
15031489
.iter()
1504-
.find_map(|b| {
1505-
match b {
1506-
RenderBlock::Variants { selected, body_blocks, .. } => Some((*selected, body_blocks)),
1507-
_ => None,
1508-
}
1490+
.find_map(|b| match b {
1491+
RenderBlock::Variants { selected, body_blocks, .. } => Some((*selected, body_blocks)),
1492+
_ => None,
15091493
})
15101494
.expect("expected Variants");
15111495
assert_eq!(v.0, 1);
15121496
let body_yaml: String = v
15131497
.1
15141498
.iter()
1515-
.filter_map(|b| {
1516-
match b {
1517-
RenderBlock::Yaml(s) => Some(s.as_str()),
1518-
_ => None,
1519-
}
1499+
.filter_map(|b| match b {
1500+
RenderBlock::Yaml(s) => Some(s.as_str()),
1501+
_ => None,
15201502
})
15211503
.collect();
15221504
assert!(body_yaml.contains("x-tag: second"), "expected second variant in body: {body_yaml}");
@@ -1579,11 +1561,9 @@ mod tests {
15791561

15801562
let yaml: String = blocks
15811563
.iter()
1582-
.filter_map(|b| {
1583-
match b {
1584-
RenderBlock::Yaml(s) => Some(s.as_str()),
1585-
_ => None,
1586-
}
1564+
.filter_map(|b| match b {
1565+
RenderBlock::Yaml(s) => Some(s.as_str()),
1566+
_ => None,
15871567
})
15881568
.collect();
15891569

@@ -1622,11 +1602,9 @@ mod tests {
16221602
let blocks = walk(value, components);
16231603
let yaml: String = blocks
16241604
.iter()
1625-
.filter_map(|b| {
1626-
match b {
1627-
RenderBlock::Yaml(s) => Some(s.as_str()),
1628-
_ => None,
1629-
}
1605+
.filter_map(|b| match b {
1606+
RenderBlock::Yaml(s) => Some(s.as_str()),
1607+
_ => None,
16301608
})
16311609
.collect();
16321610

@@ -1782,11 +1760,9 @@ mod tests {
17821760

17831761
let field_lines: Vec<String> = blocks
17841762
.iter()
1785-
.filter_map(|b| {
1786-
match b {
1787-
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1788-
_ => None,
1789-
}
1763+
.filter_map(|b| match b {
1764+
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1765+
_ => None,
17901766
})
17911767
.collect();
17921768

@@ -1833,11 +1809,9 @@ mod tests {
18331809
let blocks = walk_annotated(value, HashMap::new());
18341810
let field_lines: Vec<String> = blocks
18351811
.iter()
1836-
.filter_map(|b| {
1837-
match b {
1838-
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1839-
_ => None,
1840-
}
1812+
.filter_map(|b| match b {
1813+
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1814+
_ => None,
18411815
})
18421816
.collect();
18431817

@@ -1865,11 +1839,9 @@ mod tests {
18651839
let blocks = walk_annotated(value, HashMap::new());
18661840
let field_lines: Vec<String> = blocks
18671841
.iter()
1868-
.filter_map(|b| {
1869-
match b {
1870-
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1871-
_ => None,
1872-
}
1842+
.filter_map(|b| match b {
1843+
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1844+
_ => None,
18731845
})
18741846
.collect();
18751847

@@ -1898,11 +1870,9 @@ mod tests {
18981870

18991871
let field_lines: Vec<String> = blocks
19001872
.iter()
1901-
.filter_map(|b| {
1902-
match b {
1903-
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1904-
_ => None,
1905-
}
1873+
.filter_map(|b| match b {
1874+
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1875+
_ => None,
19061876
})
19071877
.collect();
19081878
assert!(field_lines.iter().any(|l: &String| l.contains("name (string)?")), "merged name: {field_lines:?}");
@@ -1922,23 +1892,19 @@ mod tests {
19221892

19231893
let variants = blocks
19241894
.iter()
1925-
.find_map(|b| {
1926-
match b {
1927-
RenderBlock::Variants { choices, body_blocks, .. } => Some((choices, body_blocks)),
1928-
_ => None,
1929-
}
1895+
.find_map(|b| match b {
1896+
RenderBlock::Variants { choices, body_blocks, .. } => Some((choices, body_blocks)),
1897+
_ => None,
19301898
})
19311899
.expect("expected Variants block");
19321900
assert_eq!(variants.0, &vec!["A".to_string(), "B".to_string()]);
19331901

19341902
let body_field_lines: Vec<String> = variants
19351903
.1
19361904
.iter()
1937-
.filter_map(|b| {
1938-
match b {
1939-
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1940-
_ => None,
1941-
}
1905+
.filter_map(|b| match b {
1906+
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
1907+
_ => None,
19421908
})
19431909
.collect();
19441910
assert!(
@@ -2000,11 +1966,9 @@ mod tests {
20001966

20011967
let yaml: String = blocks
20021968
.iter()
2003-
.filter_map(|b| {
2004-
match b {
2005-
RenderBlock::Yaml(s) => Some(s.as_str()),
2006-
_ => None,
2007-
}
1969+
.filter_map(|b| match b {
1970+
RenderBlock::Yaml(s) => Some(s.as_str()),
1971+
_ => None,
20081972
})
20091973
.collect();
20101974
assert!(!yaml.is_empty(), "fallback YAML should be non-empty: {yaml}");
@@ -2286,11 +2250,9 @@ mod tests {
22862250
let blocks = walk_annotated(value, HashMap::new());
22872251
let field_lines: Vec<String> = blocks
22882252
.iter()
2289-
.filter_map(|b| {
2290-
match b {
2291-
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
2292-
_ => None,
2293-
}
2253+
.filter_map(|b| match b {
2254+
RenderBlock::AnnotatedField { field_line, .. } => Some(field_line.iter().map(|(_, t)| t.as_str()).collect()),
2255+
_ => None,
22942256
})
22952257
.collect();
22962258

0 commit comments

Comments
 (0)