#Trouble accepting closure in trait
7 messages · Page 1 of 1 (latest)
pub trait PoolForEach {
fn for_each_pool<F>(&self, each_fn: F) -> ()
where
F: Fn(&OsmosisKnownPoolListing);
fn store_as_map(&self, storage: &mut dyn Storage, map: StoredPools) -> () {
self.for_each_pool(|pool: OsmosisKnownPoolListing| {
map.save(storage, &pool.out_denom, &pool.pool_id);
});
}
}
impl PoolForEach for OsmoPools {
fn for_each_pool<F>(&self, each_fn: F) -> ()
where
F: Fn(&OsmosisKnownPoolListing),
{
self.iter().for_each(|(_, pool_listing)| {
if let Some(listing) = pool_listing.downcast_ref::<OsmosisKnownPoolListing>() {
each_fn(listing)
}
})
}
}
error[E0631]: type mismatch in closure arguments
--> packages/osmosis-destinations/src/pools.rs:59:14
|
59 | self.for_each_pool(|pool: OsmosisKnownPoolListing| {
| ^^^^^^^^^^^^^ ------------------------------- found signature defined here
| |
| expected due to this
|
= note: expected closure signature `for<'a> fn(&'a OsmosisKnownPoolListing) -> _`
found closure signature `fn(OsmosisKnownPoolListing) -> _`
note: required by a bound in `PoolForEach::for_each_pool`
You're passing OsmosisKnownPoolListing instead of &OsmosisKnownPoolListing
self.for_each_pool(|pool: OsmosisKnownPoolListing| {
// v should have a ref ^
F: Fn(&OsmosisKnownPoolListing),