From 836692e73cff0356e409a9ba5b4887b86809d4ca Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 28 Nov 2022 17:57:16 +0100 Subject: Widow and orphan prevention --- src/doc.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/doc.rs b/src/doc.rs index 5d395be4..93cae90f 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -32,7 +32,7 @@ pub struct Metadata { } /// A partial layout result. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Clone, Eq, PartialEq)] pub struct Fragment(Vec); impl Fragment { @@ -60,6 +60,11 @@ impl Fragment { self.0.into_iter().next().unwrap() } + /// Extract the frames. + pub fn into_frames(self) -> Vec { + self.0 + } + /// Iterate over the contained frames. pub fn iter(&self) -> std::slice::Iter { self.0.iter() @@ -71,6 +76,15 @@ impl Fragment { } } +impl Debug for Fragment { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self.0.as_slice() { + [frame] => frame.fmt(f), + frames => frames.fmt(f), + } + } +} + impl IntoIterator for Fragment { type Item = Frame; type IntoIter = std::vec::IntoIter; @@ -121,6 +135,11 @@ impl Frame { Self { size, baseline: None, elements: Arc::new(vec![]) } } + /// Whether the frame contains no elements. + pub fn is_empty(&self) -> bool { + self.elements.is_empty() + } + /// The size of the frame. pub fn size(&self) -> Size { self.size -- cgit v1.2.3