From 3d078f7c6420526d47bd50c06217b2feaab35cb2 Mon Sep 17 00:00:00 2001 From: Olaf Buddenhagen Date: Wed, 9 Dec 2015 19:29:11 +0100 Subject: [PATCH 1/2] HashCache: Apply trait bounds on type itself, rather than only the impl I don't think there is any reason to keep the container more generic than its (only) implementation -- the constraints are necessary for this container to work at all. Defining the constraints on the type itself also enables use of #[derive(Debug)]. --- components/util/cache.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/util/cache.rs b/components/util/cache.rs index 7a3dcfa980f..2efb6a4e781 100644 --- a/components/util/cache.rs +++ b/components/util/cache.rs @@ -12,7 +12,10 @@ use std::hash::{Hash, Hasher, SipHasher}; use std::slice::Iter; -pub struct HashCache { +pub struct HashCache + where K: Clone + PartialEq + Eq + Hash, + V: Clone, +{ entries: HashMap>, } From c5ede5851ee2b31e71d50e58660fc4882a15febd Mon Sep 17 00:00:00 2001 From: Olaf Buddenhagen Date: Wed, 9 Dec 2015 19:35:14 +0100 Subject: [PATCH 2/2] Derive Debug on FontGroup and its components --- components/gfx/font.rs | 6 ++++-- components/gfx/font_template.rs | 2 +- components/gfx/platform/freetype/font.rs | 1 + components/gfx/platform/freetype/font_context.rs | 4 ++-- components/gfx/platform/freetype/font_template.rs | 2 +- components/gfx/platform/macos/font.rs | 1 + components/gfx/platform/macos/font_context.rs | 2 +- components/gfx/platform/macos/font_template.rs | 3 ++- components/gfx/text/shaping/harfbuzz.rs | 2 ++ components/util/cache.rs | 1 + 10 files changed, 16 insertions(+), 8 deletions(-) diff --git a/components/gfx/font.rs b/components/gfx/font.rs index 2ed72e55203..ed43372d318 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -85,6 +85,7 @@ pub struct FontMetrics { pub type SpecifiedFontStyle = FontStyle; +#[derive(Debug)] pub struct Font { pub handle: FontHandle, pub metrics: FontMetrics, @@ -111,7 +112,7 @@ bitflags! { } /// Various options that control text shaping. -#[derive(Clone, Eq, PartialEq, Hash, Copy)] +#[derive(Clone, Eq, PartialEq, Hash, Copy, Debug)] pub struct ShapingOptions { /// Spacing to add between each letter. Corresponds to the CSS 2.1 `letter-spacing` property. /// NB: You will probably want to set the `IGNORE_LIGATURES_SHAPING_FLAG` if this is non-null. @@ -125,7 +126,7 @@ pub struct ShapingOptions { } /// An entry in the shape cache. -#[derive(Clone, Eq, PartialEq, Hash)] +#[derive(Clone, Eq, PartialEq, Hash, Debug)] pub struct ShapeCacheEntry { text: String, options: ShapingOptions, @@ -206,6 +207,7 @@ impl Font { } } +#[derive(Debug)] pub struct FontGroup { pub fonts: SmallVec<[Rc>; 8]>, } diff --git a/components/gfx/font_template.rs b/components/gfx/font_template.rs index 45becf31d5c..0b4cd6900ef 100644 --- a/components/gfx/font_template.rs +++ b/components/gfx/font_template.rs @@ -14,7 +14,7 @@ use style::computed_values::{font_stretch, font_weight}; /// to be expanded or refactored when we support more of the font styling parameters. /// /// NB: If you change this, you will need to update `style::properties::compute_font_hash()`. -#[derive(Clone, Copy, Eq, Hash, Deserialize, Serialize)] +#[derive(Clone, Copy, Eq, Hash, Deserialize, Serialize, Debug)] pub struct FontTemplateDescriptor { pub weight: font_weight::T, pub stretch: font_stretch::T, diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs index cbb785919c7..66769d200cd 100644 --- a/components/gfx/platform/freetype/font.rs +++ b/components/gfx/platform/freetype/font.rs @@ -45,6 +45,7 @@ impl FontTableMethods for FontTable { } } +#[derive(Debug)] pub struct FontHandle { // The font binary. This must stay valid for the lifetime of the font, // if the font is created using FT_Memory_Face. diff --git a/components/gfx/platform/freetype/font_context.rs b/components/gfx/platform/freetype/font_context.rs index ccd3d40a395..0bb1137a472 100644 --- a/components/gfx/platform/freetype/font_context.rs +++ b/components/gfx/platform/freetype/font_context.rs @@ -70,7 +70,7 @@ pub type UserPtr = *mut User; // WARNING: We need to be careful how we use this struct. See the comment about Rc<> in // FontContextHandle. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct FreeTypeLibraryHandle { pub ctx: FT_Library, mem: FT_Memory, @@ -98,7 +98,7 @@ impl HeapSizeOf for FreeTypeLibraryHandle { } } -#[derive(Clone, HeapSizeOf)] +#[derive(Clone, HeapSizeOf, Debug)] pub struct FontContextHandle { // WARNING: FreeTypeLibraryHandle contains raw pointers, is clonable, and also implements // `Drop`. This field needs to be Rc<> to make sure that the `drop` function is only called diff --git a/components/gfx/platform/freetype/font_template.rs b/components/gfx/platform/freetype/font_template.rs index 6a86aa9e264..30f4ffd5437 100644 --- a/components/gfx/platform/freetype/font_template.rs +++ b/components/gfx/platform/freetype/font_template.rs @@ -10,7 +10,7 @@ use string_cache::Atom; /// The identifier is an absolute path, and the bytes /// field is the loaded data that can be passed to /// freetype and azure directly. -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Debug)] pub struct FontTemplateData { pub bytes: Vec, pub identifier: Atom, diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index c9e464a0eb2..a0667245cbe 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -57,6 +57,7 @@ impl FontTableMethods for FontTable { } } +#[derive(Debug)] pub struct FontHandle { pub font_data: Arc, pub ctfont: CTFont, diff --git a/components/gfx/platform/macos/font_context.rs b/components/gfx/platform/macos/font_context.rs index ca718de09ca..e260f84b17b 100644 --- a/components/gfx/platform/macos/font_context.rs +++ b/components/gfx/platform/macos/font_context.rs @@ -4,7 +4,7 @@ use util::mem::HeapSizeOf; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct FontContextHandle { ctx: () } diff --git a/components/gfx/platform/macos/font_template.rs b/components/gfx/platform/macos/font_template.rs index 7e922a6292c..d6ee6b9f3f0 100644 --- a/components/gfx/platform/macos/font_template.rs +++ b/components/gfx/platform/macos/font_template.rs @@ -17,7 +17,7 @@ use string_cache::Atom; /// The identifier is a PostScript font name. The /// CTFont object is cached here for use by the /// paint functions that create CGFont references. -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Debug)] pub struct FontTemplateData { /// The `CTFont` object, if present. This is cached here so that we don't have to keep creating /// `CTFont` instances over and over. It can always be recreated from the `identifier` and/or @@ -64,6 +64,7 @@ impl FontTemplateData { } } +#[derive(Debug)] pub struct CachedCTFont(Mutex>); impl Deref for CachedCTFont { diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index 800ba9f2557..47d6756d346 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -134,11 +134,13 @@ impl ShapedGlyphData { } } +#[derive(Debug)] struct FontAndShapingOptions { font: *mut Font, options: ShapingOptions, } +#[derive(Debug)] pub struct Shaper { hb_face: *mut hb_face_t, hb_font: *mut hb_font_t, diff --git a/components/util/cache.rs b/components/util/cache.rs index 2efb6a4e781..deb87405d1f 100644 --- a/components/util/cache.rs +++ b/components/util/cache.rs @@ -12,6 +12,7 @@ use std::hash::{Hash, Hasher, SipHasher}; use std::slice::Iter; +#[derive(Debug)] pub struct HashCache where K: Clone + PartialEq + Eq + Hash, V: Clone,