diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-03-30 20:51:09 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-03-30 20:58:46 +0100 |
| commit | 5ca303ecadff190800dd55a5a5ae224dc28a3920 (patch) | |
| tree | a49504b831981de1041a3f7f0ca44a3892f14ef1 /src/engine | |
| parent | adfd7dd0735d8a4efeac634c53bbf386e91a4c41 (diff) | |
Make things more consistent ♻
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/mod.rs | 16 | ||||
| -rw-r--r-- | src/engine/size.rs | 5 |
2 files changed, 12 insertions, 9 deletions
diff --git a/src/engine/mod.rs b/src/engine/mod.rs index baad9bac..daec2fbb 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -10,10 +10,10 @@ pub use size::Size; /// The core typesetting engine, transforming an abstract syntax tree into a document. -pub(crate) struct Engine<'a> { +pub struct Engine<'t> { // Immutable - tree: &'a SyntaxTree<'a>, - ctx: &'a Context<'a>, + tree: &'t SyntaxTree<'t>, + ctx: &'t Context<'t>, // Mutable fonts: Vec<Font>, @@ -23,22 +23,22 @@ pub(crate) struct Engine<'a> { current_width: Size, } -impl<'a> Engine<'a> { +impl<'t> Engine<'t> { /// Create a new generator from a syntax tree. - pub fn new(tree: &'a SyntaxTree<'a>, context: &'a Context<'a>) -> Engine<'a> { + pub(crate) fn new(tree: &'t SyntaxTree<'t>, context: &'t Context<'t>) -> Engine<'t> { Engine { tree, ctx: context, - fonts: Vec::new(), + fonts: vec![], active_font: 0, - text_commands: Vec::new(), + text_commands: vec![], current_line: String::new(), current_width: Size::zero(), } } /// Generate the abstract document. - pub fn typeset(mut self) -> TypeResult<Document> { + pub(crate) fn typeset(mut self) -> TypeResult<Document> { // Load font defined by style let mut font = None; let filter = FontFilter::new(&self.ctx.style.font_families); diff --git a/src/engine/size.rs b/src/engine/size.rs index f66641c0..bf79a3c4 100644 --- a/src/engine/size.rs +++ b/src/engine/size.rs @@ -5,7 +5,7 @@ use std::ops::*; /// A general size (unit of length) type. -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Default)] pub struct Size { /// The size in typographic points (1/72 inches). points: f32, @@ -62,6 +62,7 @@ impl Debug for Size { } impl PartialOrd for Size { + #[inline] fn partial_cmp(&self, other: &Size) -> Option<Ordering> { self.points.partial_cmp(&other.points) } @@ -70,12 +71,14 @@ impl PartialOrd for Size { impl Neg for Size { type Output = Size; + #[inline] fn neg(self) -> Size { Size { points: -self.points } } } impl Sum for Size { + #[inline] fn sum<I>(iter: I) -> Size where I: Iterator<Item=Size> { iter.fold(Size::zero(), Add::add) } |
