Skip to content
This repository was archived by the owner on May 28, 2024. It is now read-only.

Commit 88f555d

Browse files
committed
Macro-ize some common trait bounds
1 parent 0320a59 commit 88f555d

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/parser.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ impl FromCowStr for ::string_cache::Atom {
3232
}
3333

3434
macro_rules! with_bounds {
35-
($( $HeapSizeOf: tt )*) => {
35+
($( $CommonBounds: tt )*) => {
3636
/// This trait allows to define the parser implementation in regards
3737
/// of pseudo-classes/elements
3838
pub trait SelectorImpl: Sized + Debug {
39-
type AttrValue: Clone + Display + Eq + FromCowStr + Hash $($HeapSizeOf)*;
40-
type Identifier: Clone + Display + Eq + FromCowStr + Hash + BloomHash $($HeapSizeOf)*;
41-
type ClassName: Clone + Display + Eq + FromCowStr + Hash + BloomHash $($HeapSizeOf)*;
42-
type LocalName: Clone + Display + Eq + FromCowStr + Hash + BloomHash $($HeapSizeOf)*
39+
type AttrValue: $($CommonBounds)* + Display + FromCowStr;
40+
type Identifier: $($CommonBounds)* + Display + FromCowStr + BloomHash;
41+
type ClassName: $($CommonBounds)* + Display + FromCowStr + BloomHash;
42+
type LocalName: $($CommonBounds)* + Display + FromCowStr + BloomHash
4343
+ Borrow<Self::BorrowedLocalName>;
44-
type NamespaceUrl: Clone + Display + Eq + Default + Hash + BloomHash $($HeapSizeOf)*
44+
type NamespaceUrl: $($CommonBounds)* + Display + Default + BloomHash
4545
+ Borrow<Self::BorrowedNamespaceUrl>;
46-
type NamespacePrefix: Clone + Display + Eq + Default + Hash + FromCowStr $($HeapSizeOf)*;
46+
type NamespacePrefix: $($CommonBounds)* + Display + Default + FromCowStr;
4747
type BorrowedNamespaceUrl: ?Sized + Eq;
4848
type BorrowedLocalName: ?Sized + Eq + Hash;
4949

5050
/// non tree-structural pseudo-classes
5151
/// (see: https://drafts.csswg.org/selectors/#structural-pseudos)
52-
type NonTSPseudoClass: Clone + Eq + Hash + PartialEq + Sized + ToCss $($HeapSizeOf)*;
52+
type NonTSPseudoClass: $($CommonBounds)* + Sized + ToCss;
5353

5454
/// pseudo-elements
55-
type PseudoElement: Sized + PartialEq + Eq + Clone + Hash + ToCss $($HeapSizeOf)*;
55+
type PseudoElement: $($CommonBounds)* + Sized + ToCss;
5656

5757
/// Declares if the following "attribute exists" selector is considered
5858
/// "common" enough to be shareable. If that's not the case, when matching
@@ -86,11 +86,17 @@ macro_rules! with_bounds {
8686
}
8787
}
8888

89+
macro_rules! with_heap_size_bound {
90+
($( $HeapSizeOf: tt )*) => {
91+
with_bounds!(Clone + Eq + Hash $($HeapSizeOf)*);
92+
}
93+
}
94+
8995
#[cfg(feature = "heap_size")]
90-
with_bounds!(+ ::heapsize::HeapSizeOf);
96+
with_heap_size_bound!(+ ::heapsize::HeapSizeOf);
9197

9298
#[cfg(not(feature = "heap_size"))]
93-
with_bounds!();
99+
with_heap_size_bound!();
94100

95101
pub struct ParserContext<Impl: SelectorImpl> {
96102
pub in_user_agent_stylesheet: bool,

0 commit comments

Comments
 (0)