summaryrefslogtreecommitdiff
path: root/src/doc.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc.rs')
-rw-r--r--src/doc.rs21
1 files changed, 20 insertions, 1 deletions
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<Frame>);
impl Fragment {
@@ -60,6 +60,11 @@ impl Fragment {
self.0.into_iter().next().unwrap()
}
+ /// Extract the frames.
+ pub fn into_frames(self) -> Vec<Frame> {
+ self.0
+ }
+
/// Iterate over the contained frames.
pub fn iter(&self) -> std::slice::Iter<Frame> {
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<Frame>;
@@ -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