Skip to content

Commit

Permalink
dev: add more debug impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Dec 5, 2023
1 parent bb18703 commit aac5e4f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
24 changes: 23 additions & 1 deletion core/src/vector/flat_ir/layout.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::fmt;
use std::{
borrow::Cow,
collections::HashMap,
Expand Down Expand Up @@ -180,7 +181,7 @@ pub struct LayoutRegionRepr<T> {
}

/// Describing
#[derive(Debug, Clone)]
#[derive(Clone)]
#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
pub enum LayoutRegion {
Expand Down Expand Up @@ -283,6 +284,27 @@ impl Index<usize> for LayoutRegion {
}
}

impl fmt::Debug for LayoutRegion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ByScalar(v) => {
write!(f, "LayoutRegion({:?})", v.kind)?;

f.debug_map()
.entries(v.layouts.iter().map(|(ref k, ref v)| (k, v)))
.finish()
}
Self::ByStr(v) => {
write!(f, "LayoutRegion({:?})", v.kind)?;

f.debug_map()
.entries(v.layouts.iter().map(|(ref k, ref v)| (k, v)))
.finish()
}
}
}
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
Expand Down
44 changes: 42 additions & 2 deletions core/src/vector/flat_ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! │[`SvgDocument`]│◄───────────────┤[`MultiSvgDocument`]│
//! └───────────────┘ └────────────────────┘
use core::fmt;
use std::sync::Arc;

mod module;
Expand Down Expand Up @@ -204,7 +205,7 @@ impl FromIterator<(GlyphItem, (GlyphRef, FontRef))> for GlyphPack {
}

/// Describing reference to a page
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
pub struct Page {
Expand All @@ -214,8 +215,20 @@ pub struct Page {
pub size: Size,
}

impl fmt::Debug for Page {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Page({}, {:.3}x{:.3})",
self.content.as_svg_id(""),
self.size.x.0,
self.size.y.0
)
}
}

/// metadata that can be attached to a module.
#[derive(Debug, Clone)]
#[derive(Clone)]
#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[repr(C, align(32))]
Expand All @@ -226,6 +239,32 @@ pub enum PageMetadata {
Custom(Vec<(ImmutStr, ImmutBytes)>),
}

impl fmt::Debug for PageMetadata {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PageMetadata::GarbageCollection(v) => f
.debug_struct("GarbageCollection")
.field("len", &v.len())
.finish(),
PageMetadata::Item(v) => f.debug_struct("Item").field("len", &v.0.len()).finish(),
PageMetadata::Glyph(v) => f
.debug_struct("Glyph")
.field("len", &v.items.len())
.field("base", &v.incremental_base)
.finish(),
PageMetadata::Custom(v) => {
write!(f, "Custom")?;
f.debug_map()
.entries(
v.iter()
.map(|(k, v)| (k.as_ref(), format!("Bytes({})", v.len()))),
)
.finish()
}
}
}
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
Expand Down Expand Up @@ -480,6 +519,7 @@ pub fn flatten_glyphs(
let t = match t {
GlyphItem::Image(i) => FlatGlyphItem::Image(i),
GlyphItem::Outline(p) => FlatGlyphItem::Outline(p),
GlyphItem::None => FlatGlyphItem::None,
_ => unreachable!(),
};

Expand Down

0 comments on commit aac5e4f

Please sign in to comment.