scale_info_legacy/
lib.rs

1// Copyright (C) 2024 Parity Technologies (UK) Ltd. (admin@parity.io)
2// This file is a part of the scale-info-legacy crate.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//         http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! This crate provides a set of types which build on each other. The ultimate goal is to be able to define
17//! the necessary type information needed to describe how historic Substrate types are SCALE encoded.
18//!
19//! The main types exposed here are as follows:
20//!
21//! - [`TypeRegistry`]: the lowest level type which one can populate with type information (via [`TypeRegistry::insert()`]
22//!   and [`TypeRegistry::insert_runtime_api()`]), and then query to resolve some type name to the relevant information
23//!   (via [`TypeRegistry::resolve_type()`] and [`TypeRegistry::runtime_api()`]).
24//! - [`TypeRegistrySet`]: a set of the above, which will resolve types (via [`TypeRegistrySet::resolve_type()`]) by working
25//!   through the inner type registries until it finds the relevant information (or doesn't find anything). This allows us
26//!   to combine type registries in different ways to alter how we resolve things.
27//! - [`ChainTypeRegistry`]: this type is constructed by deserializing some JSON (or similar) which describes all of the
28//!   types that we need to know about on a given chain. The main function here is [`ChainTypeRegistry::for_spec_version()`],
29//!   which returns a [`TypeRegistrySet`] for resolving types for the given spec version.
30//!
31//! We also expose an [`InsertName`], which is built by parsing type names like `Vec<T>` from strings, and used in
32//! [`TypeRegistry::insert()`] to insert types, and then [`LookupName`], which is built by parsing type names like
33//! `Vec<T>`, `[u8; 32]` and `(bool, u32)` and is used to lookup the corresponding type information via [`TypeRegistry::resolve_type()`]
34//! and similar. Finally, [`TypeShape`] is an enum used to describe the shape of the type inserted via [`TypeRegistry::insert()`].
35//!
36//! This crate, like `scale-info`, can be used in conjunction with crates like:
37//!
38//! - [`scale-decode`](https://github.com/paritytech/scale-decode) to decode SCALE encoded bytes
39//!   into custom types based on this type information.
40//! - [`scale-encode`](https://github.com/paritytech/scale-encode) to SCALE encode custom types
41//!   into bytes based on this type information.
42//! - [`scale-value`](https://github.com/paritytech/scale-value) to SCALE encode or decode from a
43//!   `Value` type (a bit like `serde_json`'s `Value` type).
44
45#![no_std]
46#![deny(missing_docs)]
47
48extern crate alloc;
49
50pub mod chain_types;
51pub mod insert_name;
52pub mod lookup_name;
53pub mod type_registry;
54pub mod type_registry_set;
55pub mod type_shape;
56
57#[cfg(test)]
58mod test_utils;
59
60// Export the main types here for ease of use:
61pub use {
62    chain_types::ChainTypeRegistry, insert_name::InsertName, lookup_name::LookupName,
63    type_registry::RuntimeApiInput, type_registry::TypeRegistry,
64    type_registry_set::TypeRegistrySet, type_shape::TypeShape,
65};