pub trait Describe<C>{
    const TYPE_ID: RustTypeId;

    // Required method
    fn type_data() -> TypeData<C, RustTypeId>;

    // Provided method
    fn add_all_dependencies(aggregator: &mut TypeAggregator<C>) { ... }
}
Expand description

The Describe trait allows a type to describe how to interpret and validate a corresponding SBOR payload.

Each unique interpretation/validation of a type should have its own distinct type in the schema. Uniqueness of a type in the schema is defined by its RustTypeId.

Required Associated Constants§

source

const TYPE_ID: RustTypeId

The TYPE_ID should give a unique identifier for its SBOR schema type. An SBOR schema type capture details about the SBOR payload, how it should be interpreted, validated and displayed.

Conceptually, each type should have a unique id based on:

  • Its SBOR type, structure and child types
  • Any validation that should be applied so that the codec can decode a payload successfully
  • How it should be named or its contents be displayed
  • Any additional data associated with the type which may be added in future (eg i18n or further validation)

For example:

  • An Array<u32> and Array<u64> are different types because they have different structures
  • Two types named “Content” may be in different namepaces, and wrap different kinds of content, so be different types
  • The tuple (T1, T2) is a different type for each T1 and T2 because they have different structures
  • Types which are intended to be “transparent” to SBOR such as pointers/smart pointers/etc are equivalent to their wrapper type, so should inherit the TYPE_ID of the wrapped type.

Most basic types without additional validation have an associated “Well Known” type, which is intended to save room in the schema. Any non-well known types are “Novel” and should be generated for each type.

If needing to generate a novel type id, this can be generated via helper methods on RustTypeId:

impl Describe<C: CustomTypeSchema, T1: Describe<C>> for MyType<T1> {
    const TYPE_ID: RustTypeId = RustTypeId::complex(stringify!(MyType), &[T1::TYPE_ID]);
}

Required Methods§

source

fn type_data() -> TypeData<C, RustTypeId>

Returns the local schema for the given type.

If the TYPE_ID is well_known, then this type data must match the corresponding well known type data.

Provided Methods§

source

fn add_all_dependencies(aggregator: &mut TypeAggregator<C>)

For each type referenced in get_local_type_data, we need to ensure that the type and all of its own references get added to the aggregator.

For direct/simple type dependencies, simply call aggregator.add_child_type_and_descendents::<D>() for each dependency.

For more complicated type dependencies, where new types are being created (EG where a dependent type is being customised/mutated via annotations on the parent type - such as a TypeName override), then the algorithm should be:

  • Step 1: For each (possibly customised) type dependency needed directly by this type:

    • Create a new mutated mutated_type_id for the underlying type plus its mutation
    • Use mutated_type_id in the relevant place/s in get_local_type_data
    • In add_all_dependencies add a line aggregator.add_child_type(mutated_type_id, mutated_local_type_data)
  • Step 2: For each (base/unmutated) type dependency D:

    • In add_all_dependencies add a line aggregator.add_schema_descendents::<D>()

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<C> Describe<C> for bool

source§

impl<C> Describe<C> for i8

source§

impl<C> Describe<C> for i16

source§

impl<C> Describe<C> for i32

source§

impl<C> Describe<C> for i64

source§

impl<C> Describe<C> for i128

source§

impl<C> Describe<C> for isize

source§

impl<C> Describe<C> for str

source§

impl<C> Describe<C> for u8

source§

impl<C> Describe<C> for u16

source§

impl<C> Describe<C> for u32

source§

impl<C> Describe<C> for u64

source§

impl<C> Describe<C> for u128

source§

impl<C> Describe<C> for ()

source§

impl<C> Describe<C> for usize

source§

impl<C, T0> Describe<C> for (T0,)

source§

impl<C, T0, T1> Describe<C> for (T0, T1)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>,

source§

impl<C, T0, T1, T2> Describe<C> for (T0, T1, T2)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>,

source§

impl<C, T0, T1, T2, T3> Describe<C> for (T0, T1, T2, T3)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4> Describe<C> for (T0, T1, T2, T3, T4)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5> Describe<C> for (T0, T1, T2, T3, T4, T5)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6> Describe<C> for (T0, T1, T2, T3, T4, T5, T6)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>, T11: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>, T11: Describe<C>, T12: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>, T11: Describe<C>, T12: Describe<C>, T13: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>, T11: Describe<C>, T12: Describe<C>, T13: Describe<C>, T14: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>, T11: Describe<C>, T12: Describe<C>, T13: Describe<C>, T14: Describe<C>, T15: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>, T11: Describe<C>, T12: Describe<C>, T13: Describe<C>, T14: Describe<C>, T15: Describe<C>, T16: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>, T11: Describe<C>, T12: Describe<C>, T13: Describe<C>, T14: Describe<C>, T15: Describe<C>, T16: Describe<C>, T17: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>, T11: Describe<C>, T12: Describe<C>, T13: Describe<C>, T14: Describe<C>, T15: Describe<C>, T16: Describe<C>, T17: Describe<C>, T18: Describe<C>,

source§

impl<C, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19> Describe<C> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19)
where C: CustomTypeKind<RustTypeId>, T0: Describe<C>, T1: Describe<C>, T2: Describe<C>, T3: Describe<C>, T4: Describe<C>, T5: Describe<C>, T6: Describe<C>, T7: Describe<C>, T8: Describe<C>, T9: Describe<C>, T10: Describe<C>, T11: Describe<C>, T12: Describe<C>, T13: Describe<C>, T14: Describe<C>, T15: Describe<C>, T16: Describe<C>, T17: Describe<C>, T18: Describe<C>, T19: Describe<C>,

source§

impl<C, T> Describe<C> for &T

source§

impl<C, T> Describe<C> for [T]

source§

impl<C, T, const N: usize> Describe<C> for [T; N]

Implementors§

source§

impl Describe<ScryptoCustomTypeKind> for ParseBlsPublicKeyError

source§

impl Describe<ScryptoCustomTypeKind> for ParseBlsSignatureError

source§

impl Describe<ScryptoCustomTypeKind> for PublicKey

source§

impl Describe<ScryptoCustomTypeKind> for PublicKeyHash

source§

impl Describe<ScryptoCustomTypeKind> for OwnValidation

source§

impl Describe<ScryptoCustomTypeKind> for ReferenceValidation

source§

impl Describe<ScryptoCustomTypeKind> for ScryptoCustomTypeKind

source§

impl Describe<ScryptoCustomTypeKind> for ScryptoCustomTypeValidation

source§

impl Describe<ScryptoCustomTypeKind> for NonFungibleLocalId

source§

impl Describe<ScryptoCustomTypeKind> for RoyaltyAmount

source§

impl Describe<ScryptoCustomTypeKind> for GenericSubstitution

source§

impl Describe<ScryptoCustomTypeKind> for Ed25519PublicKey

source§

impl Describe<ScryptoCustomTypeKind> for Ed25519PublicKeyHash

source§

impl Describe<ScryptoCustomTypeKind> for Secp256k1PublicKey

source§

impl Describe<ScryptoCustomTypeKind> for Secp256k1PublicKeyHash

source§

impl Describe<ScryptoCustomTypeKind> for Own

source§

impl Describe<ScryptoCustomTypeKind> for Reference

source§

impl Describe<ScryptoCustomTypeKind> for Decimal

source§

impl Describe<ScryptoCustomTypeKind> for PreciseDecimal

source§

impl Describe<ScryptoCustomTypeKind> for Instant

source§

impl Describe<ScryptoCustomTypeKind> for UtcDateTime

source§

impl Describe<ScryptoCustomTypeKind> for ComponentAddress

source§

impl Describe<ScryptoCustomTypeKind> for GlobalAddress

source§

impl Describe<ScryptoCustomTypeKind> for InternalAddress

source§

impl Describe<ScryptoCustomTypeKind> for PackageAddress

source§

impl Describe<ScryptoCustomTypeKind> for ResourceAddress

source§

impl Describe<ScryptoCustomTypeKind> for GlobalAddressReservation

source§

impl Describe<ScryptoCustomTypeKind> for BlueprintTypeIdentifier

source§

impl Describe<NoCustomTypeKind> for PublicKey

source§

impl Describe<NoCustomTypeKind> for PublicKeyHash

source§

impl Describe<NoCustomTypeKind> for Ed25519PublicKey

source§

impl Describe<NoCustomTypeKind> for Ed25519PublicKeyHash

source§

impl Describe<NoCustomTypeKind> for Secp256k1PublicKey

source§

impl Describe<NoCustomTypeKind> for Secp256k1PublicKeyHash

source§

impl Describe<NoCustomTypeKind> for Instant

source§

impl Describe<NoCustomTypeKind> for UtcDateTime

source§

impl<'a, C, B> Describe<C> for Cow<'a, B>
where C: CustomTypeKind<RustTypeId>, B: 'a + ToOwned + Describe<C> + ?Sized,

source§

const TYPE_ID: RustTypeId = B::TYPE_ID

source§

impl<C> Describe<C> for NoCustomTypeKind

source§

impl<C> Describe<C> for NoCustomTypeValidation

source§

impl<C> Describe<C> for SchemaValidationError

source§

impl<C> Describe<C> for ChildNames

source§

impl<C> Describe<C> for DecodeError

source§

impl<C> Describe<C> for EncodeError

source§

impl<C> Describe<C> for LocalTypeId

source§

impl<C> Describe<C> for RustTypeId

source§

impl<C> Describe<C> for LengthValidation

source§

impl<C> Describe<C> for NovelTypeMetadata

source§

impl<C> Describe<C> for String

source§

impl<C> Describe<C> for TypeMetadata

source§

impl<C> Describe<C> for WellKnownTypeId

source§

impl<C, K, V> Describe<C> for BTreeMap<K, V>
where C: CustomTypeKind<RustTypeId>, K: Describe<C>, V: Describe<C>,

source§

impl<C, K, V> Describe<C> for HashMap<K, V>
where C: CustomTypeKind<RustTypeId>, K: Describe<C>, V: Describe<C>,

source§

const TYPE_ID: RustTypeId = BTreeMap<K, V>::TYPE_ID

source§

impl<C, K, V> Describe<C> for IndexMap<K, V>
where C: CustomTypeKind<RustTypeId>, K: Describe<C>, V: Describe<C>,

source§

const TYPE_ID: RustTypeId = BTreeMap<K, V>::TYPE_ID

source§

impl<C, L, C0> Describe<C0> for TypeKind<C, L>

source§

impl<C, T> Describe<C> for Option<T>

source§

impl<C, T> Describe<C> for BTreeSet<T>

source§

impl<C, T> Describe<C> for Box<T>

source§

const TYPE_ID: RustTypeId = T::TYPE_ID

source§

impl<C, T> Describe<C> for Rc<T>

source§

const TYPE_ID: RustTypeId = T::TYPE_ID

source§

impl<C, T> Describe<C> for RefCell<T>

source§

const TYPE_ID: RustTypeId = T::TYPE_ID

source§

impl<C, T> Describe<C> for Vec<T>

source§

const TYPE_ID: RustTypeId = <[T]>::TYPE_ID

source§

impl<C, T> Describe<C> for HashSet<T>

source§

const TYPE_ID: RustTypeId = BTreeSet<T>::TYPE_ID

source§

impl<C, T> Describe<C> for IndexSet<T>

source§

const TYPE_ID: RustTypeId = BTreeSet<T>::TYPE_ID

source§

impl<C, T, E> Describe<C> for Result<T, E>
where C: CustomTypeKind<RustTypeId>, T: Describe<C>, E: Describe<C>,

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for ParseHashError

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for ScryptoCustomValueKind

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for NonFungibleIdType

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for RoundingMode

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for TimeComparisonOperator

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for DateTimeError

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for EntityType

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for SubstateKey

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for Bls12381G1PublicKey

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for Bls12381G2Signature

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for Ed25519Signature

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for Hash

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for Secp256k1Signature

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for NetworkDefinition

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for Epoch

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for Round

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for NodeId

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for PartitionNumber

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for PartitionOffset

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for SchemaHash

source§

impl<C: CustomTypeKind<RustTypeId>> Describe<C> for ScopedTypeId

source§

impl<E, C> Describe<C> for TypeValidation<E>

source§

impl<Ext, C> Describe<C> for RawValue<'_, Ext>

source§

impl<S, C> Describe<C> for VersionedSchema<S>

source§

impl<S, C> Describe<C> for SchemaV1<S>

source§

impl<T, C> Describe<C> for NumericValidation<T>

source§

impl<T, C: CustomTypeKind<RustTypeId>> Describe<C> for FullyScopedTypeId<T>
where T: Describe<C> + Into<NodeId>,

source§

impl<X, Y, C> Describe<C> for Value<X, Y>

source§

impl<X, Y, C> Describe<C> for EnumVariantValue<X, Y>