I have a function that updates my Listing struct in DoubleMap Storage. How can I mutate the storage with given optional params?
pub fn update_listing(
origin: OriginFor<T>,
property_id: T::Hash,
is_active: Option<bool>,
content: Option<Content<T::MaxContentLength>>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(Listings::<T>::get(&property_id, &who).is_some(), Error::<T>::ListingNotFound);
Listings::<T>::mutate(&property_id, &who, |o_listing| {
let listing = o_listing.as_mut().unwrap();
if let Some(is_active) = is_active {
listing.is_active = is_active;
}
if let Some(content) = content {
listing.content = content;
}
Some(listing)
});
Self::deposit_event(Event::ListingUpdated(property_id, who));
Ok(())
}
error: lifetime may not live long enough
--> pallets/listing/src/lib.rs:131:5
|
123 | Listings::<T>::mutate(&property_id, &who, |mut o_listing| {
| -------------- return type of closure is std::option::Option<&'2 mut Listing<<T as frame_system::Config>::BlockNumber, <T as pallet::Config>::MaxContentLength>>
| |
| has type `&'1 mut std::option::Option<Listing<<T as frame_system::Config>::BlockNumber, <T as pallet::Config>::MaxContentLength>>`
...
131 | Some(listing)
| ^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`