【发布时间】:2021-11-22 08:54:38
【问题描述】:
这是我的 StorageMap:
#[pallet::getter(fn hotel_status)]
/// Keeps track of what accounts own what Kitty.
pub(super) type HotelStatus<T: Config> = StorageMap<
_,
Twox64Concat,
T::AccountId,
Gender,
>;
我想使用 try_mutate 来改变性别,因为 AccountId 已经存在于地图中,或者插入一个新条目。这是完整的外部:
#[pallet::weight(0)]
pub fn activate_hotel(
origin: OriginFor<T>,
hotel: T::AccountId,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
log::info!("signer ID: {:?}.", sender);
let hotel_status = <HotelStatus<T>>::get(&hotel);
ensure!(hotel_status == Some(Gender::Active), <Error<T>>::HotelAlreadyActive);
<HotelStatus<T>>::try_mutate(hotel, |status| {
status = Gender::Active;
}).map_err(|_| <HotelStatus<T>>::insert(hotel, Gender::Active));
Ok(())
}
我得到的错误是
mismatched types
expected mutable reference, found enum `pallet::Gender`
note: expected mutable reference `&mut std::option::Option<pallet::Gender>`
found enum `pallet::Gender`rustc(E0308)
lib.rs(297, 14): expected mutable reference, found enum `pallet::Gender`
substrate 教程仅给出了一个示例,其中值为 vec,他们尝试将新元素推送到其上,因此我不知道如何改变枚举或原始类型(例如字符串、数字)。
【问题讨论】: