From e10b3d838a75ea351f8477e07f2e1e647f4539dc Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 27 Sep 2021 13:40:56 +0200 Subject: Fix panic due to bad alignments in stack function --- src/layout/par.rs | 6 +++--- src/layout/stack.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src/layout') diff --git a/src/layout/par.rs b/src/layout/par.rs index 847612b9..beb7a1d6 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -96,9 +96,9 @@ impl From for LayoutNode { impl Debug for ParChild { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { - ParChild::Spacing(v) => write!(f, "Spacing({:?})", v), - ParChild::Text(text, ..) => write!(f, "Text({:?})", text), - ParChild::Any(node, ..) => f.debug_tuple("Any").field(node).finish(), + Self::Spacing(v) => write!(f, "Spacing({:?})", v), + Self::Text(text, ..) => write!(f, "Text({:?})", text), + Self::Any(node, ..) => node.fmt(f), } } } diff --git a/src/layout/stack.rs b/src/layout/stack.rs index 4b148ad8..e3416e6b 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -1,3 +1,5 @@ +use std::fmt::{self, Debug, Formatter}; + use super::*; /// A node that stacks its children. @@ -14,7 +16,6 @@ pub struct StackNode { } /// A child of a stack node. -#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub enum StackChild { /// Spacing between other nodes. @@ -39,6 +40,15 @@ impl From for LayoutNode { } } +impl Debug for StackChild { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Self::Spacing(v) => write!(f, "Spacing({:?})", v), + Self::Any(node, _) => node.fmt(f), + } + } +} + /// Performs stack layout. struct StackLayouter<'a> { /// The stack node to layout. -- cgit v1.2.3