11use std:: ops:: Add ;
22
33/// An abstraction for a generic tree node.
4- pub trait Node < ' n > {
4+ pub trait Node {
55 /// The type of this [Node]'s [kind][Node::kind].
66 ///
77 /// Only [Node]s of the equal _kind_ can replace each other.
88 type Kind : PartialEq ;
99
1010 /// Returns this [Node]'s _kind_.
11- fn kind ( & ' n self ) -> Self :: Kind ;
11+ fn kind ( & self ) -> Self :: Kind ;
1212
1313 /// The type of this [Node]'s [weight][Node::weight].
1414 ///
@@ -18,16 +18,18 @@ pub trait Node<'n> {
1818 /// Returns the cost of inserting or deleting this [Node].
1919 ///
2020 /// A [Node]'s weight should be independent of the weight of its children.
21- fn weight ( & ' n self ) -> Self :: Weight ;
21+ fn weight ( & self ) -> Self :: Weight ;
2222}
2323
2424/// An abstraction for a recursive tree.
25- pub trait Tree < ' t > : ' t + Node < ' t > {
25+ pub trait Tree : Node {
2626 /// A type that can iterate over this [Tree]'s [children][Tree::children].
27- type Children : IntoIterator < Item = & ' t Self > ;
27+ type Children < ' c > : ' c + IntoIterator < Item = & ' c Self >
28+ where
29+ Self : ' c ;
2830
2931 /// Returns this [Tree]'s immediate children.
30- fn children ( & ' t self ) -> Self :: Children ;
32+ fn children ( & self ) -> Self :: Children < ' _ > ;
3133}
3234
3335#[ cfg( test) ]
@@ -58,7 +60,10 @@ mod tests {
5860 }
5961 }
6062
61- fn tree < K : ' static + PartialEq + Arbitrary > ( size : Size ) -> impl Strategy < Value = MockTree < K > > {
63+ fn tree < K > ( size : Size ) -> impl Strategy < Value = MockTree < K > >
64+ where
65+ K : ' static + Copy + PartialEq + Arbitrary ,
66+ {
6267 let depth = size. depth as u32 ;
6368 let breadth = size. breadth as u32 ;
6469 let size = ( breadth. pow ( depth + 1 ) - 1 ) / ( breadth - 1 ) / 2 ; // half the maximum number of nodes
@@ -71,13 +76,13 @@ mod tests {
7176 }
7277
7378 #[ derive( Debug , Default , Clone , PartialEq , Eq , Hash , From ) ]
74- pub ( crate ) struct MockTree < K : PartialEq > {
79+ pub ( crate ) struct MockTree < K : Copy + PartialEq > {
7580 kind : K ,
7681 weight : u8 ,
7782 children : Vec < Self > ,
7883 }
7984
80- impl < K : ' static + PartialEq + Arbitrary > Arbitrary for MockTree < K > {
85+ impl < K : ' static + Copy + PartialEq + Arbitrary > Arbitrary for MockTree < K > {
8186 type Parameters = Size ;
8287 type Strategy = BoxedStrategy < Self > ;
8388
@@ -86,39 +91,36 @@ mod tests {
8691 }
8792 }
8893
89- impl < ' n , K : ' n + PartialEq > Node < ' n > for MockTree < K > {
90- type Kind = & ' n K ;
91- fn kind ( & ' n self ) -> Self :: Kind {
92- & self . kind
94+ impl < K : Copy + PartialEq > Node for MockTree < K > {
95+ type Kind = K ;
96+ fn kind ( & self ) -> Self :: Kind {
97+ self . kind
9398 }
9499
95100 type Weight = u64 ;
96- fn weight ( & ' n self ) -> Self :: Weight {
101+ fn weight ( & self ) -> Self :: Weight {
97102 self . weight . into ( )
98103 }
99104 }
100105
101- impl < ' t , K : ' t + PartialEq > Tree < ' t > for MockTree < K > {
102- type Children = & ' t [ Self ] ;
103- fn children ( & ' t self ) -> Self :: Children {
106+ impl < K : Copy + PartialEq > Tree for MockTree < K > {
107+ type Children < ' c > = & ' c [ Self ]
108+ where
109+ Self : ' c ;
110+
111+ fn children ( & self ) -> Self :: Children < ' _ > {
104112 & self . children
105113 }
106114 }
107115
108- impl < K : PartialEq > Fold for MockTree < K >
109- where
110- Self : for < ' t > Tree < ' t , Children = & ' t [ Self ] > ,
111- {
116+ impl < K : Copy + PartialEq > Fold for MockTree < K > {
112117 fn fold < R , Fn : FnMut ( R , & Self ) -> R > ( & self , init : R , f : & mut Fn ) -> R {
113118 self . children ( ) . fold ( f ( init, self ) , f)
114119 }
115120 }
116121
117- impl < K : PartialEq , W : Default + Copy + Add < Output = W > > Cost for MockTree < K >
118- where
119- Self : for < ' t > Tree < ' t , Weight = W , Children = & ' t [ Self ] > ,
120- {
121- type Output = W ;
122+ impl < K : Copy + PartialEq > Cost for MockTree < K > {
123+ type Output = <Self as Node >:: Weight ;
122124
123125 #[ inline]
124126 fn cost ( & self ) -> Self :: Output {
0 commit comments