From 5becb32ba463d6b0ace914ab06bb237483a94fbc Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 17 Oct 2021 14:38:48 +0200 Subject: Introduce page / block / inline levels --- src/eval/array.rs | 6 ++---- src/eval/dict.rs | 6 ++---- src/eval/template.rs | 50 +++++++++++++++++++++++++------------------------- src/eval/walk.rs | 10 +++++----- 4 files changed, 34 insertions(+), 38 deletions(-) (limited to 'src/eval') diff --git a/src/eval/array.rs b/src/eval/array.rs index 17192cb3..f6adee6d 100644 --- a/src/eval/array.rs +++ b/src/eval/array.rs @@ -7,6 +7,7 @@ use std::rc::Rc; use super::Value; use crate::diag::StrResult; +use crate::util::RcExt; /// Create a new [`Array`] from values. #[allow(unused_macros)] @@ -169,10 +170,7 @@ impl IntoIterator for Array { type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { - match Rc::try_unwrap(self.0) { - Ok(vec) => vec.into_iter(), - Err(rc) => (*rc).clone().into_iter(), - } + Rc::take(self.0).into_iter() } } diff --git a/src/eval/dict.rs b/src/eval/dict.rs index c0ddf328..e7a46b40 100644 --- a/src/eval/dict.rs +++ b/src/eval/dict.rs @@ -6,6 +6,7 @@ use std::rc::Rc; use super::{Str, Value}; use crate::diag::StrResult; +use crate::util::RcExt; /// Create a new [`Dict`] from key-value pairs. #[allow(unused_macros)] @@ -135,10 +136,7 @@ impl IntoIterator for Dict { type IntoIter = std::collections::btree_map::IntoIter; fn into_iter(self) -> Self::IntoIter { - match Rc::try_unwrap(self.0) { - Ok(map) => map.into_iter(), - Err(rc) => (*rc).clone().into_iter(), - } + Rc::take(self.0).into_iter() } } diff --git a/src/eval/template.rs b/src/eval/template.rs index 63916339..11ea3f56 100644 --- a/src/eval/template.rs +++ b/src/eval/template.rs @@ -6,9 +6,9 @@ use std::rc::Rc; use super::Str; use crate::diag::StrResult; -use crate::geom::{Align, Dir, GenAxis, Length, Linear, Sides, Size, SpecAxis}; +use crate::geom::{Align, Dir, GenAxis, Length, Linear, Sides, Size}; use crate::layout::{ - Decoration, LayoutNode, LayoutTree, PadNode, PageRun, ParChild, ParNode, StackChild, + BlockNode, Decoration, InlineNode, PadNode, PageNode, ParChild, ParNode, StackChild, StackNode, }; use crate::style::Style; @@ -34,9 +34,9 @@ enum TemplateNode { /// Spacing. Spacing(GenAxis, Linear), /// An inline node builder. - Inline(Rc LayoutNode>, Vec), + Inline(Rc InlineNode>, Vec), /// An block node builder. - Block(Rc LayoutNode>), + Block(Rc BlockNode>), /// Save the current style. Save, /// Restore the last saved style. @@ -55,7 +55,7 @@ impl Template { pub fn from_inline(f: F) -> Self where F: Fn(&Style) -> T + 'static, - T: Into, + T: Into, { let node = TemplateNode::Inline(Rc::new(move |s| f(s).into()), vec![]); Self(Rc::new(vec![node])) @@ -65,7 +65,7 @@ impl Template { pub fn from_block(f: F) -> Self where F: Fn(&Style) -> T + 'static, - T: Into, + T: Into, { let node = TemplateNode::Block(Rc::new(move |s| f(s).into())); Self(Rc::new(vec![node])) @@ -164,10 +164,10 @@ impl Template { /// Build the layout tree resulting from instantiating the template with the /// given style. - pub fn to_tree(&self, style: &Style) -> LayoutTree { + pub fn to_pages(&self, style: &Style) -> Vec { let mut builder = Builder::new(style, true); builder.template(self); - builder.build_tree() + builder.build_pages() } /// Repeat this template `n` times. @@ -243,8 +243,8 @@ struct Builder { style: Style, /// Snapshots of the style. snapshots: Vec