diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-16 18:52:26 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-16 19:15:03 +0200 |
| commit | 9462fb17b390c57846b9215217ca7c32b649f0a5 (patch) | |
| tree | bd6f96fea83c5e757c8f0eefefe5c0347784f00b /src/exec | |
| parent | cb0aab3cfab2122a87d1d221290f7178b4291758 (diff) | |
Convert single-field structs to tuple structs
Diffstat (limited to 'src/exec')
| -rw-r--r-- | src/exec/context.rs | 4 | ||||
| -rw-r--r-- | src/exec/mod.rs | 9 | ||||
| -rw-r--r-- | src/exec/state.rs | 23 |
3 files changed, 15 insertions, 21 deletions
diff --git a/src/exec/context.rs b/src/exec/context.rs index 2d419a56..9b235c29 100644 --- a/src/exec/context.rs +++ b/src/exec/context.rs @@ -75,7 +75,7 @@ impl ExecContext { /// Push a word space into the active paragraph. pub fn push_word_space(&mut self) { - self.stack.par.push_soft(self.make_text_node(" ")); + self.stack.par.push_soft(self.make_text_node(' ')); } /// Push any node into the active paragraph. @@ -107,7 +107,7 @@ impl ExecContext { /// Apply a forced line break. pub fn linebreak(&mut self) { - self.stack.par.push_hard(self.make_text_node("\n")); + self.stack.par.push_hard(self.make_text_node('\n')); } /// Apply a forced paragraph break. diff --git a/src/exec/mod.rs b/src/exec/mod.rs index ac4c1fca..dc3054d2 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -106,8 +106,7 @@ impl ExecWithMap for ListItem { impl ExecWithMap for EnumItem { fn exec_with_map(&self, ctx: &mut ExecContext, map: &ExprMap) { let mut label = EcoString::new(); - write!(&mut label, "{}", self.number.unwrap_or(1)).unwrap(); - label.push('.'); + write!(&mut label, "{}.", self.number.unwrap_or(1)).unwrap(); exec_item(ctx, label, &self.body, map); } } @@ -115,7 +114,7 @@ impl ExecWithMap for EnumItem { fn exec_item(ctx: &mut ExecContext, label: EcoString, body: &SyntaxTree, map: &ExprMap) { let label = ctx.exec_stack(|ctx| ctx.push_text(label)); let body = ctx.exec_tree_stack(body, map); - let stack = StackNode { + ctx.push_into_stack(StackNode { dirs: Gen::new(ctx.state.dirs.main, ctx.state.dirs.cross), aspect: None, children: vec![ @@ -123,9 +122,7 @@ fn exec_item(ctx: &mut ExecContext, label: EcoString, body: &SyntaxTree, map: &E StackChild::Spacing(ctx.state.font.size / 2.0), StackChild::Any(body.into(), Gen::default()), ], - }; - - ctx.push_into_stack(stack); + }); } impl Exec for Value { diff --git a/src/exec/state.rs b/src/exec/state.rs index ce30e042..56cf5f2e 100644 --- a/src/exec/state.rs +++ b/src/exec/state.rs @@ -91,7 +91,7 @@ impl Default for PageState { fn default() -> Self { let paper = PAPER_A4; Self { - class: paper.class, + class: paper.class(), size: paper.size(), margins: Sides::splat(None), } @@ -171,19 +171,16 @@ impl FontState { /// The resolved family iterator. pub fn families(&self) -> impl Iterator<Item = &str> + Clone { - let head = if self.monospace { - self.families.monospace.as_slice() - } else { - &[] - }; + let head = self + .monospace + .then(|| self.families.monospace.as_slice()) + .unwrap_or_default(); - let core = self.families.list.iter().flat_map(move |family: &FontFamily| { - match family { - FontFamily::Named(name) => std::slice::from_ref(name), - FontFamily::Serif => &self.families.serif, - FontFamily::SansSerif => &self.families.sans_serif, - FontFamily::Monospace => &self.families.monospace, - } + let core = self.families.list.iter().flat_map(move |family| match family { + FontFamily::Named(name) => std::slice::from_ref(name), + FontFamily::Serif => &self.families.serif, + FontFamily::SansSerif => &self.families.sans_serif, + FontFamily::Monospace => &self.families.monospace, }); head.iter() |
