@@ -131,7 +131,10 @@ impl From<Predicate> for middleware::Predicate {
131131 match v {
132132 Predicate :: Native ( p) => p. into ( ) ,
133133 Predicate :: BatchSelf ( i) => middleware:: Predicate :: BatchSelf ( i) ,
134- Predicate :: Custom ( CustomPredicateRef ( pb, i) ) => {
134+ Predicate :: Custom ( CustomPredicateRef {
135+ batch : pb,
136+ index : i,
137+ } ) => {
135138 let cpb: middleware:: CustomPredicateBatch = Arc :: unwrap_or_clone ( pb) . into ( ) ;
136139 middleware:: Predicate :: Custom ( middleware:: CustomPredicateRef ( Arc :: new ( cpb) , i) )
137140 }
@@ -144,31 +147,40 @@ impl fmt::Display for Predicate {
144147 match self {
145148 Self :: Native ( p) => write ! ( f, "{:?}" , p) ,
146149 Self :: BatchSelf ( i) => write ! ( f, "self.{}" , i) ,
147- Self :: Custom ( CustomPredicateRef ( pb, i) ) => write ! ( f, "{}.{}" , pb. name, i) ,
150+ Self :: Custom ( CustomPredicateRef { batch, index } ) => {
151+ write ! ( f, "{}.{}" , batch. name, index)
152+ }
148153 }
149154 }
150155}
151156
152157#[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize , JsonSchema ) ]
153- pub struct CustomPredicateRef ( pub Arc < CustomPredicateBatch > , pub usize ) ;
158+ pub struct CustomPredicateRef {
159+ pub batch : Arc < CustomPredicateBatch > ,
160+ pub index : usize ,
161+ }
154162
155163impl From < CustomPredicateRef > for middleware:: CustomPredicateRef {
156164 fn from ( v : CustomPredicateRef ) -> Self {
157- let cpb: middleware:: CustomPredicateBatch = Arc :: unwrap_or_clone ( v. 0 ) . into ( ) ;
158- middleware:: CustomPredicateRef ( Arc :: new ( cpb) , v. 1 )
165+ let cpb: middleware:: CustomPredicateBatch = Arc :: unwrap_or_clone ( v. batch ) . into ( ) ;
166+ middleware:: CustomPredicateRef ( Arc :: new ( cpb) , v. index )
159167 }
160168}
161169
162170impl CustomPredicateRef {
171+ pub fn new ( batch : Arc < CustomPredicateBatch > , index : usize ) -> Self {
172+ Self { batch, index }
173+ }
174+
163175 pub fn arg_len ( & self ) -> usize {
164- self . 0 . predicates [ self . 1 ] . args_len
176+ self . batch . predicates [ self . index ] . args_len
165177 }
166178 pub fn match_against ( & self , statements : & [ Statement ] ) -> Result < HashMap < usize , Value > > {
167179 let mut bindings = HashMap :: new ( ) ;
168180 // Single out custom predicate, replacing batch-self
169181 // references with custom predicate references.
170182 let custom_predicate = {
171- let cp = & Arc :: unwrap_or_clone ( self . 0 . clone ( ) ) . predicates [ self . 1 ] ;
183+ let cp = & Arc :: unwrap_or_clone ( self . batch . clone ( ) ) . predicates [ self . index ] ;
172184 CustomPredicate {
173185 conjunction : cp. conjunction ,
174186 statements : cp
@@ -177,9 +189,9 @@ impl CustomPredicateRef {
177189 . map ( |StatementTmpl ( p, args) | {
178190 StatementTmpl (
179191 match p {
180- Predicate :: BatchSelf ( i) => {
181- Predicate :: Custom ( CustomPredicateRef ( self . 0 . clone ( ) , * i) )
182- }
192+ Predicate :: BatchSelf ( i) => Predicate :: Custom (
193+ CustomPredicateRef :: new ( self . batch . clone ( ) , * i) ,
194+ ) ,
183195 _ => p. clone ( ) ,
184196 } ,
185197 args. to_vec ( ) ,
@@ -526,7 +538,7 @@ mod tests {
526538 let eth_friend = eth_friend_batch ( & params) ?;
527539
528540 // This batch only has 1 predicate, so we pick it already for convenience
529- let eth_friend = Predicate :: Custom ( CustomPredicateRef ( eth_friend, 0 ) ) ;
541+ let eth_friend = Predicate :: Custom ( CustomPredicateRef :: new ( eth_friend, 0 ) ) ;
530542
531543 let eth_dos_batch = eth_dos_batch ( & params) ?;
532544 let eth_dos_batch_mw: middleware:: CustomPredicateBatch =
0 commit comments