[−][src]Crate scale_info
Efficient and compact serialization of Rust types.
This library provides structures to easily retrieve compile-time type information at runtime and also to serialize this information in a compact form.
Registry
At the heart of its functionality is the crate::Registry
that acts as cache for
known strings and types in order to efficiently deduplicate them and thus
compactify the overall serialization.
Type Information
Information about types is provided via the crate::TypeInfo
trait.
This trait should be implemented for all types that are serializable. For this the library provides implementations for all commonly used Rust standard types and provides derive macros for simpler implementation of user provided custom types.
Compaction Forms
There is an uncompact form, called crate::form::MetaForm
that acts as a bridge from
compile-time type information at runtime in order to easily retrieve all
information needed to uniquely identify types.
The compact form is retrieved by the crate::IntoCompact
trait and internally used
by the crate::Registry
in order to convert the uncompact strings and types into
their compact form.
Symbols and Namespaces
Since symbol names are often shared across type boundaries the crate::Registry
also deduplicates them. To differentiate two types sharing the same name
namespaces are used. Commonly the namespace is equal to the one where the
type has been defined in. For Rust prelude types such as std::option::Option
and
std::result::Result
the root namespace (empty namespace) is used.
To use this library simply use the crate::form::MetaForm
initially with your own data
structures and at best make them generic over the crate::form::Form
trait just as has
been done in this crate with crate::TypeInfo
in order to go for a simple
implementation of crate::IntoCompact
. Use a single instance of the crate::Registry
for
compaction and provide this registry instance upon serialization. Done.
A usage example can be found in ink! here: https://github.com/paritytech/ink/blob/master/abi/src/specs.rs
Modules
build | Builders for defining metadata for variant types (enums), and composite types (structs). They are designed to allow only construction of valid definitions. |
form | Provides some form definitions. |
interner | Interning data structure and associated symbol definitions. |
Macros
tuple_meta_type | Takes a number of types and returns a vector that contains their respective
|
Structs
Field | A field of a struct like data type. |
MetaType | A metatype abstraction. |
Path | Represents the path of a type definition. |
Registry | The registry for compaction of type identifiers and definitions. |
Type | A |
TypeDefArray | An array type. |
TypeDefComposite | A composite type, consisting of either named (struct) or unnamed (tuple struct) fields |
TypeDefSequence | A type to refer to a sequence of elements of the same type. |
TypeDefTuple | A type to refer to tuple types. |
TypeDefVariant | A Enum type (consisting of variants). |
Variant | A struct enum variant with either named (struct) or unnamed (tuple struct) fields. |
Enums
PathError | An error that may be encountered upon constructing namespaces. |
TypeDef | The possible types a SCALE encodable Rust value could have. |
TypeDefPrimitive | A primitive Rust type. |
Traits
IntoCompact | Compacts the implementor using a registry. |
Metadata | A super trait that shall be implemented by all types implementing |
TypeInfo | Implementors return their meta type information. |