From c384e524800bb55da0c5614f412e7d835ed67945 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 29 Apr 2019 13:41:00 +0200 Subject: =?UTF-8?q?Improve=20code=20quality=20=F0=9F=8E=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/engine/mod.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/engine') diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 37fce8dc..622dfc5e 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -3,7 +3,9 @@ use std::cell::{RefCell, Ref}; use std::collections::HashMap; use std::mem::swap; + use smallvec::SmallVec; + use crate::syntax::{SyntaxTree, Node}; use crate::doc::{Document, Page, Text, TextCommand}; use crate::font::{Font, FontFamily, FontInfo, FontError}; @@ -36,7 +38,8 @@ pub struct Engine<'a> { impl<'a> Engine<'a> { /// Create a new generator from a syntax tree. - pub(crate) fn new(tree: &'a SyntaxTree, context: &'a Context<'a>) -> Engine<'a> { + #[inline] + pub fn new(tree: &'a SyntaxTree, context: &'a Context<'a>) -> Engine<'a> { Engine { tree, ctx: context, @@ -52,7 +55,7 @@ impl<'a> Engine<'a> { } /// Generate the abstract document. - pub(crate) fn typeset(mut self) -> TypeResult { + pub fn typeset(mut self) -> TypesetResult { // Start by moving to a suitable position. self.move_start(); @@ -91,7 +94,7 @@ impl<'a> Engine<'a> { } /// Write a word. - fn write_word(&mut self, word: &str) -> TypeResult<()> { + fn write_word(&mut self, word: &str) -> TypesetResult<()> { // Contains pairs of (characters, font_index, char_width). let mut chars_with_widths = SmallVec::<[(char, usize, Size); 12]>::new(); @@ -127,7 +130,7 @@ impl<'a> Engine<'a> { } /// Write the space character: `' '`. - fn write_space(&mut self) -> TypeResult<()> { + fn write_space(&mut self) -> TypesetResult<()> { let space_width = self.char_width(' ', &self.get_font_for(' ')?.1); if !self.would_overflow(space_width) && self.current_line_width > Size::zero() { self.write_word(" ")?; @@ -190,7 +193,7 @@ impl<'a> Engine<'a> { } /// Load a font that has the character we need. - fn get_font_for(&self, character: char) -> TypeResult<(usize, Ref)> { + fn get_font_for(&self, character: char) -> TypesetResult<(usize, Ref)> { self.font_loader.get(FontQuery { families: &self.ctx.style.font_families, italic: self.italic, @@ -426,9 +429,11 @@ pub enum TypesetError { Font(FontError), } +/// The result type for typesetting. +pub type TypesetResult = Result; + error_type! { err: TypesetError, - res: TypeResult, show: f => match err { TypesetError::MissingFont => write!(f, "missing font"), TypesetError::Font(err) => write!(f, "font error: {}", err), -- cgit v1.2.3