From 924a27bc37f29769da225184ec1b35f9b96dbab5 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 9 Feb 2023 14:11:00 +0100 Subject: Move `Fragment` into library --- src/doc.rs | 81 -------------------------------------------------------------- 1 file changed, 81 deletions(-) (limited to 'src') diff --git a/src/doc.rs b/src/doc.rs index d4ad2d93..d399162f 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -27,87 +27,6 @@ pub struct Document { pub author: Option, } -/// A partial layout result. -#[derive(Clone)] -pub struct Fragment(Vec); - -impl Fragment { - /// Create a fragment from a single frame. - pub fn frame(frame: Frame) -> Self { - Self(vec![frame]) - } - - /// Create a fragment from multiple frames. - pub fn frames(frames: Vec) -> Self { - Self(frames) - } - - /// The number of frames in the fragment. - pub fn len(&self) -> usize { - self.0.len() - } - - /// Extract the first and only frame. - /// - /// Panics if there are multiple frames. - #[track_caller] - pub fn into_frame(self) -> Frame { - assert_eq!(self.0.len(), 1, "expected exactly one frame"); - 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() - } - - /// Iterate over the contained frames. - pub fn iter_mut(&mut self) -> std::slice::IterMut { - self.0.iter_mut() - } -} - -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; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl<'a> IntoIterator for &'a Fragment { - type Item = &'a Frame; - type IntoIter = std::slice::Iter<'a, Frame>; - - fn into_iter(self) -> Self::IntoIter { - self.0.iter() - } -} - -impl<'a> IntoIterator for &'a mut Fragment { - type Item = &'a mut Frame; - type IntoIter = std::slice::IterMut<'a, Frame>; - - fn into_iter(self) -> Self::IntoIter { - self.0.iter_mut() - } -} - /// A finished layout with elements at fixed positions. #[derive(Default, Clone)] pub struct Frame { -- cgit v1.2.3