radix_common/data/scrypto/
custom_value_kind.rs

1use crate::internal_prelude::*;
2
3pub const VALUE_KIND_REFERENCE: u8 = 0x80;
4pub const VALUE_KIND_OWN: u8 = 0x90;
5pub const VALUE_KIND_DECIMAL: u8 = 0xa0;
6pub const VALUE_KIND_PRECISE_DECIMAL: u8 = 0xb0;
7pub const VALUE_KIND_NON_FUNGIBLE_LOCAL_ID: u8 = 0xc0;
8
9#[cfg_attr(feature = "fuzzing", derive(::arbitrary::Arbitrary))]
10#[cfg_attr(
11    feature = "serde",
12    derive(::serde::Serialize, ::serde::Deserialize),
13    serde(tag = "type")
14)]
15#[derive(Copy, Debug, Clone, PartialEq, Eq, Sbor)]
16pub enum ScryptoCustomValueKind {
17    Reference,
18    Own,
19    Decimal,
20    PreciseDecimal,
21    NonFungibleLocalId,
22}
23
24impl From<ScryptoCustomValueKind> for ValueKind<ScryptoCustomValueKind> {
25    fn from(custom_value_kind: ScryptoCustomValueKind) -> Self {
26        ValueKind::Custom(custom_value_kind)
27    }
28}
29
30impl CustomValueKind for ScryptoCustomValueKind {
31    fn as_u8(&self) -> u8 {
32        match self {
33            Self::Reference => VALUE_KIND_REFERENCE,
34            Self::Own => VALUE_KIND_OWN,
35            Self::Decimal => VALUE_KIND_DECIMAL,
36            Self::PreciseDecimal => VALUE_KIND_PRECISE_DECIMAL,
37            Self::NonFungibleLocalId => VALUE_KIND_NON_FUNGIBLE_LOCAL_ID,
38        }
39    }
40
41    fn from_u8(id: u8) -> Option<Self> {
42        match id {
43            VALUE_KIND_REFERENCE => Some(ScryptoCustomValueKind::Reference),
44            VALUE_KIND_OWN => Some(ScryptoCustomValueKind::Own),
45            VALUE_KIND_DECIMAL => Some(ScryptoCustomValueKind::Decimal),
46            VALUE_KIND_PRECISE_DECIMAL => Some(ScryptoCustomValueKind::PreciseDecimal),
47            VALUE_KIND_NON_FUNGIBLE_LOCAL_ID => Some(ScryptoCustomValueKind::NonFungibleLocalId),
48            _ => None,
49        }
50    }
51}