git.delta.rocks / unique-network / refs/commits / 4b3d05886c9a

difftreelog

source

pallets/proxy-rmrk-core/src/misc.rs1.4 KiBsourcehistory
1use super::*;2use codec::{Encode, Decode};34#[macro_export]5macro_rules! map_common_err_to_proxy {6    (match $err:ident { $($common_err:ident => $proxy_err:ident),+ }) => {7        $(8            if $err == <CommonError<T>>::$common_err.into() {9                return <Error<T>>::$proxy_err.into()10            } else11        )+ {12            $err13        }14    };15}1617pub trait RmrkDecode<T: Decode + Default, S> {18	fn decode_or_default(&self) -> T;19}2021// todo fail if unwrap doesn't work22impl<T: Decode + Default, S> RmrkDecode<T, S> for BoundedVec<u8, S> {23	fn decode_or_default(&self) -> T {24		let mut value = self.as_slice();2526		T::decode(&mut value).unwrap_or_default()27	}28}2930pub trait RmrkRebind<T, S> {31	fn rebind(&self) -> BoundedVec<u8, S>;32}3334// todo fail if unwrap doesn't work35impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T>36where37	BoundedVec<u8, S>: TryFrom<Vec<u8>>,38{39	fn rebind(&self) -> BoundedVec<u8, S> {40		BoundedVec::<u8, S>::try_from(self.clone().into_inner()).unwrap_or_default()41	}42}4344#[derive(Encode, Decode, PartialEq, Eq)]45pub enum CollectionType {46	Regular,47	Resource,48	Base,49}5051// todo remove default?52#[derive(Encode, Decode, PartialEq, Eq, Default)]53pub enum NftType {54	#[default]55	Regular,56	Resource,57	FixedPart,58	SlotPart,59	Theme,60}6162// todo remove default?63#[derive(Encode, Decode, PartialEq, Eq, Default)]64pub enum ResourceType {65	#[default]66	Basic,67	Composable,68	Slot,69}