Skip to content

Commit

Permalink
Make ElementRef Debug impl use Element
Browse files Browse the repository at this point in the history
The derived impl would print out the whole tree. This caused selectors
to log many GBs per minute.
  • Loading branch information
gfaster committed Jul 30, 2024
1 parent 27dd786 commit f5cc684
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/element_ref/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Element references.
use std::fmt;
use std::fmt::{self, Debug};
use std::ops::Deref;

use ego_tree::iter::{Edge, Traverse};
Expand All @@ -15,7 +15,7 @@ use crate::{Node, Selector};
///
/// This wrapper implements the `Element` trait from the `selectors` crate, which allows it to be
/// matched against CSS selectors.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct ElementRef<'a> {
node: NodeRef<'a, Node>,
}
Expand Down Expand Up @@ -116,6 +116,12 @@ impl<'a> ElementRef<'a> {
}
}

impl<'a> Debug for ElementRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Debug::fmt(self.value(), f)
}
}

impl<'a> Deref for ElementRef<'a> {
type Target = NodeRef<'a, Node>;
fn deref(&self) -> &NodeRef<'a, Node> {
Expand All @@ -131,7 +137,7 @@ pub struct Select<'a, 'b> {
nth_index_cache: NthIndexCache,
}

impl fmt::Debug for Select<'_, '_> {
impl Debug for Select<'_, '_> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Select")
.field("scope", &self.scope)
Expand Down

0 comments on commit f5cc684

Please sign in to comment.