#Trouble accepting closure in trait

7 messages · Page 1 of 1 (latest)

cedar onyx
#

hi friends, having a hard time getting down to the meat of the issue i'm having here where i can't accept a closure in my for_each_pool trait.

would love a link to documentation that can help me improve my understanding of the topic at hand as well

#
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`
obsidian blade
#

You're passing OsmosisKnownPoolListing instead of &OsmosisKnownPoolListing

shell oriole
#
self.for_each_pool(|pool: OsmosisKnownPoolListing| {
//    v should have a ref ^
F: Fn(&OsmosisKnownPoolListing),
cedar onyx
#

can't believe that's all it was

#

tyty

#

been banging my head against this forever