git.delta.rocks / unique-network / refs/commits / 4186437dc1bc

difftreelog

source

pallets/proxy-rmrk-core/src/property.rs3.0 KiBsourcehistory
1use super::*;2use core::convert::AsRef;34pub enum RmrkProperty<'r> {5    Metadata,6    CollectionType,7    RoyaltyInfo,8    Equipped,9    ResourceCollection,10    ResourcePriorities,11    ResourceType,12    PendingResourceAccept,13    PendingResourceRemoval,14    Parts,15    Base,16    Src,17    Slot,18    License,19    Thumb,20    EquippedNft,21    BaseType,22    ExternalPartId,23    EquippableList,24    ZIndex,25    ThemeName,26    ThemeProperty(&'r RmrkString),27    ThemeInherit,28}2930impl<'r> RmrkProperty<'r> {31    pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {32        fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {33            container.as_ref()34        }3536        macro_rules! key {37            ($($component:expr),+) => {38                PropertyKey::try_from([$(key!(@ &$component)),+].concat())39                    .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)40            };4142            (@ $key:expr) => {43                get_bytes($key)44            };45        }4647        match self {48            Self::Metadata => key!("metadata"),49            Self::CollectionType => key!("collection-type"),50            Self::RoyaltyInfo => key!("royalty-info"),51            Self::Equipped => key!("equipped"),52            Self::ResourceCollection => key!("resource-collection"),53            Self::ResourcePriorities => key!("resource-priorities"),54            Self::ResourceType => key!("resource-type"),55            Self::PendingResourceAccept => key!("pending-accept"),56            Self::PendingResourceRemoval => key!("pending-removal"),57            Self::Parts => key!("parts"),58            Self::Base => key!("base"),59            Self::Src => key!("src"),60            Self::Slot => key!("slot"),61            Self::License => key!("license"),62            Self::Thumb => key!("thumb"),63            Self::EquippedNft => key!("equipped-nft"),64            Self::BaseType => key!("base-type"),65            Self::ExternalPartId => key!("ext-part-id"),66            Self::EquippableList => key!("equippable-list"),67            Self::ZIndex => key!("z-index"),68            Self::ThemeName => key!("theme-name"),69            Self::ThemeProperty(name) => key!("theme-property-", name),70            Self::ThemeInherit => key!("theme-inherit"),71        }72    }73}7475#[macro_export]76macro_rules! rmrk_property {77    (Config=$cfg:ty, key: $key:ident $(($key_ext:expr))?) => {78        rmrk_property!(Config=$cfg, $crate::RmrkProperty::$key $(($key_ext))?)79    };8081    (Config=$cfg:ty, $key:ident $(($key_ext:expr))?: $value:expr) => {{82        let key = rmrk_property!(@$cfg, $crate::RmrkProperty::$key $(($key_ext))?)?;8384        let value = $value.into_property_value()85            .map_err(<$crate::Error<$cfg>>::from)?;8687        Ok::<_, $crate::Error<$cfg>>(Property {88            key,89            value,90        })91    }};9293    (@$cfg:ty, $key_enum:expr) => {94        $key_enum.to_key::<$cfg>()95    };9697    (Config=$cfg:ty, $key_enum:expr) => {98        PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key_enum)?)99            .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyKeyIsTooLong)100    };101}