From 440d24ffa0223363068ccddf3782bb84f1889033 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Fri, 7 Jul 2023 21:44:21 -0700 Subject: [PATCH] Add more Debug implementations I generally like to implement Debug on these kind of types. --- src/attrs.rs | 2 +- src/bidi_para.rs | 1 + src/buffer.rs | 4 ++++ src/buffer_line.rs | 1 + src/edit/editor.rs | 1 + src/edit/syntect.rs | 2 ++ src/edit/vi.rs | 1 + src/font/mod.rs | 9 +++++++++ src/font/system/mod.rs | 1 + src/font/system/no_std.rs | 1 + src/font/system/std.rs | 1 + src/layout.rs | 2 ++ src/lib.rs | 2 ++ src/shape.rs | 4 ++++ src/swash.rs | 7 +++++++ 15 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/attrs.rs b/src/attrs.rs index 92d90e1..eeec353 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -206,7 +206,7 @@ impl AttrsOwned { /// List of text attributes to apply to a line //TODO: have this clean up the spans when changes are made -#[derive(Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub struct AttrsList { defaults: AttrsOwned, spans: RangeMap, diff --git a/src/bidi_para.rs b/src/bidi_para.rs index fd50d0d..5a7e595 100644 --- a/src/bidi_para.rs +++ b/src/bidi_para.rs @@ -4,6 +4,7 @@ use unicode_bidi::{bidi_class, BidiClass, BidiInfo, ParagraphInfo}; /// An iterator over the paragraphs in the input text. /// It is equivalent to [`core::str::Lines`] but follows `unicode-bidi` behaviour. +#[derive(Debug)] pub struct BidiParagraphs<'text> { text: &'text str, info: alloc::vec::IntoIter, diff --git a/src/buffer.rs b/src/buffer.rs index 14a8b2f..fd85c74 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -93,6 +93,7 @@ impl Default for Affinity { } /// The position of a cursor within a [`Buffer`]. +#[derive(Debug)] pub struct LayoutCursor { pub line: usize, pub layout: usize, @@ -110,6 +111,7 @@ impl LayoutCursor { } /// A line of visible text for rendering +#[derive(Debug)] pub struct LayoutRun<'a> { /// The index of the original text line pub line_i: usize, @@ -184,6 +186,7 @@ impl<'a> LayoutRun<'a> { } /// An iterator of visible text lines, see [`LayoutRun`] +#[derive(Debug)] pub struct LayoutRunIter<'b> { buffer: &'b Buffer, line_i: usize, @@ -316,6 +319,7 @@ impl fmt::Display for Metrics { } /// A buffer of text that is shaped and laid out +#[derive(Debug)] pub struct Buffer { /// [BufferLine]s (or paragraphs) of text in the buffer pub lines: Vec, diff --git a/src/buffer_line.rs b/src/buffer_line.rs index 4ada0f9..205d4e2 100644 --- a/src/buffer_line.rs +++ b/src/buffer_line.rs @@ -4,6 +4,7 @@ use alloc::{string::String, vec::Vec}; use crate::{Align, AttrsList, FontSystem, LayoutLine, ShapeLine, Shaping, Wrap}; /// A line (or paragraph) of text that is shaped and laid out +#[derive(Debug)] pub struct BufferLine { //TODO: make this not pub(crate) text: String, diff --git a/src/edit/editor.rs b/src/edit/editor.rs index 027ce27..2374ab8 100644 --- a/src/edit/editor.rs +++ b/src/edit/editor.rs @@ -16,6 +16,7 @@ use crate::{ }; /// A wrapper of [`Buffer`] for easy editing +#[derive(Debug)] pub struct Editor { buffer: Buffer, cursor: Cursor, diff --git a/src/edit/syntect.rs b/src/edit/syntect.rs index 7a52995..62e9352 100644 --- a/src/edit/syntect.rs +++ b/src/edit/syntect.rs @@ -12,6 +12,7 @@ use crate::{ Shaping, Style, Weight, Wrap, }; +#[derive(Debug)] pub struct SyntaxSystem { pub syntax_set: SyntaxSet, pub theme_set: ThemeSet, @@ -29,6 +30,7 @@ impl SyntaxSystem { } /// A wrapper of [`Editor`] with syntax highlighting provided by [`SyntaxSystem`] +#[derive(Debug)] pub struct SyntaxEditor<'a> { editor: Editor, syntax_system: &'a SyntaxSystem, diff --git a/src/edit/vi.rs b/src/edit/vi.rs index 9756a29..b0309aa 100644 --- a/src/edit/vi.rs +++ b/src/edit/vi.rs @@ -16,6 +16,7 @@ enum Mode { SearchBackwards, } +#[derive(Debug)] pub struct ViEditor<'a> { editor: SyntaxEditor<'a>, mode: Mode, diff --git a/src/font/mod.rs b/src/font/mod.rs index 9c277a5..af3c590 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -14,6 +14,7 @@ pub use font_inner::Font; mod font_inner { use super::*; use aliasable::boxed::AliasableBox; + use core::fmt; /// A font // @@ -31,6 +32,14 @@ mod font_inner { id: fontdb::ID, } + impl fmt::Debug for Font { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Font") + .field("id", &self.id) + .finish_non_exhaustive() + } + } + pub(super) struct FontTryBuilder< RustybuzzBuilder: for<'this> FnOnce( &'this Arc + Send + Sync>, diff --git a/src/font/system/mod.rs b/src/font/system/mod.rs index b378aa9..666df05 100644 --- a/src/font/system/mod.rs +++ b/src/font/system/mod.rs @@ -15,6 +15,7 @@ pub use fontdb; pub use rustybuzz; /// A value borrowed together with an [`FontSystem`] +#[derive(Debug)] pub struct BorrowedWithFontSystem<'a, T> { pub(crate) inner: &'a mut T, pub(crate) font_system: &'a mut FontSystem, diff --git a/src/font/system/no_std.rs b/src/font/system/no_std.rs index f981061..af0f000 100644 --- a/src/font/system/no_std.rs +++ b/src/font/system/no_std.rs @@ -9,6 +9,7 @@ use alloc::{ use crate::{Attrs, Font}; /// Access system fonts +#[derive(Debug)] pub struct FontSystem { locale: String, db: fontdb::Database, diff --git a/src/font/system/std.rs b/src/font/system/std.rs index eb87bd8..4a355c0 100644 --- a/src/font/system/std.rs +++ b/src/font/system/std.rs @@ -5,6 +5,7 @@ use std::{collections::HashMap, sync::Arc}; use crate::{Attrs, AttrsOwned, Font}; /// Access system fonts +#[derive(Debug)] pub struct FontSystem { locale: String, db: fontdb::Database, diff --git a/src/layout.rs b/src/layout.rs index f25fa45..3598f30 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -52,6 +52,7 @@ pub struct LayoutGlyph { pub metadata: usize, } +#[derive(Debug)] pub struct PhysicalGlyph { /// Cache key, see [CacheKey] pub cache_key: CacheKey, @@ -81,6 +82,7 @@ impl LayoutGlyph { } /// A line of laid out glyphs +#[derive(Debug)] pub struct LayoutLine { /// Width of the line pub w: f32, diff --git a/src/lib.rs b/src/lib.rs index a07eecf..3a16321 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,6 +71,8 @@ #![deny(clippy::cast_ptr_alignment)] // Avoid panicking in without information about the panic. Use expect #![deny(clippy::unwrap_used)] +// Ensure all types have a debug impl +#![deny(missing_debug_implementations)] // This is usually a serious issue - a missing import of a define where it is interpreted // as a catch-all variable in a match, for example #![deny(unreachable_patterns)] diff --git a/src/shape.rs b/src/shape.rs index cf1c413..f2de337 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -308,6 +308,7 @@ fn shape_skip( } /// A shaped glyph +#[derive(Debug)] pub struct ShapeGlyph { pub start: usize, pub end: usize, @@ -351,6 +352,7 @@ impl ShapeGlyph { } /// A shaped word (for word wrapping) +#[derive(Debug)] pub struct ShapeWord { pub blank: bool, pub glyphs: Vec, @@ -428,6 +430,7 @@ impl ShapeWord { } /// A shaped span (for bidirectional processing) +#[derive(Debug)] pub struct ShapeSpan { pub level: unicode_bidi::Level, pub words: Vec, @@ -510,6 +513,7 @@ impl ShapeSpan { } /// A shaped line (or paragraph) +#[derive(Debug)] pub struct ShapeLine { pub rtl: bool, pub spans: Vec, diff --git a/src/swash.rs b/src/swash.rs index 363c900..f4af779 100644 --- a/src/swash.rs +++ b/src/swash.rs @@ -4,6 +4,7 @@ use alloc::collections::BTreeMap as Map; #[cfg(not(feature = "std"))] use alloc::vec::Vec; +use core::fmt; #[cfg(feature = "std")] use std::collections::HashMap as Map; use swash::scale::{image::Content, ScaleContext}; @@ -96,6 +97,12 @@ pub struct SwashCache { pub outline_command_cache: Map>>, } +impl fmt::Debug for SwashCache { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("SwashCache { .. }") + } +} + impl SwashCache { /// Create a new swash cache pub fn new() -> Self {