Skip to content

Commit f3b8601

Browse files
committed
get rid of boxed dyn
1 parent 3b53c14 commit f3b8601

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

contract/src/jar/account/v1.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,8 @@ impl AccountV1 {
129129
}
130130
}
131131

132-
type ProductFilter = dyn FnMut(&Product) -> bool;
133-
134132
impl Contract {
135-
pub(crate) fn update_account_cache(&mut self, account_id: &AccountId, filter: Option<Box<ProductFilter>>) {
133+
pub(crate) fn update_account_cache(&mut self, account_id: &AccountId, filter: Option<fn(&Product) -> bool>) {
136134
let now = env::block_timestamp_ms();
137135
let products = self.get_products(account_id, filter);
138136
let account = self.get_account_mut(account_id);
@@ -148,7 +146,7 @@ impl Contract {
148146
account.update_jar_cache(product, env::block_timestamp_ms());
149147
}
150148

151-
fn get_products(&self, account_id: &AccountId, filter: Option<Box<ProductFilter>>) -> Vec<Product> {
149+
fn get_products(&self, account_id: &AccountId, filter: Option<impl Fn(&Product) -> bool>) -> Vec<Product> {
152150
let products = self
153151
.get_account(account_id)
154152
.jars

contract/src/score/score_api.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ impl ScoreApi for Contract {
2525
for (account_id, new_score) in batch {
2626
self.update_account_cache(
2727
&account_id,
28-
Some(Box::new(|product: &Product| {
29-
matches!(product.terms, Terms::ScoreBased(_))
30-
})),
28+
Some(|product: &Product| matches!(product.terms, Terms::ScoreBased(_))),
3129
);
3230

3331
let account = self.get_account_mut(&account_id);

0 commit comments

Comments
 (0)