Crate scale_info[][src]

Expand description

Efficient and space-efficient 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 space-efficient form, aka PortableForm.

Registry

At the heart of its functionality is the Registry that acts as a cache for known types in order to efficiently deduplicate types and ensure a space-efficient serialization.

Type Information

Information about types is provided via the TypeInfo trait.

This trait should be implemented for all types that are serializable. scale-info provides implementations for all commonly used Rust standard types and a derive macro for implementing of custom types.

Forms

To bridge between compile-time type information and runtime the MetaForm is used to easily retrieve all information needed to uniquely identify types.

The MetaForm and its associated Registry can be transformed into the space-efficient form by the IntoPortable trait; it is used internally by the Registry in order to convert the expanded types into their space-efficient form.

Symbols and Namespaces

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 Option and Result the root namespace (empty namespace) is used.

To use this library simply use the MetaForm initially with your own data structures; make them generic over the Form trait just as has been done in this crate with TypeInfo in order to get a simple implementation of IntoPortable. Use a single instance of the Registry for compaction and provide this registry instance upon serialization.

A usage example can be found in ink! here: https://github.com/paritytech/ink/blob/master/abi/src/specs.rs

Modules

Builders for defining metadata for variant types (enums), and composite types (structs). They are designed to allow only construction of valid definitions.

Provides form definitions.

Interning data structure and associated symbol definitions.

Exports from std, core and alloc crates.

Macros

Takes a number of types and returns a vector that contains their respective MetaType instances.

Structs

A field of a struct-like data type.

A metatype abstraction.

Represents the path of a type definition.

A read-only registry containing types in their portable form for serialization.

The registry for space-efficient storage of type identifiers and definitions.

A Type definition with optional metadata.

An array type.

Type describing a bitvec::vec::BitVec.

A type wrapped in [Compact].

A composite type, consisting of either named (struct) or unnamed (tuple struct) fields

A type describing a PhantomData<T> type.

A type to refer to a sequence of elements of the same type.

A type to refer to tuple types.

A Enum type (consisting of variants).

A struct enum variant with either named (struct) or unnamed (tuple struct) fields.

Enums

An error that may be encountered upon constructing namespaces.

The possible types a SCALE encodable Rust value could have.

A primitive Rust type.

Traits

Convert the type definition into the portable form using a registry.

Convenience trait for implementors, combining TypeInfo and 'static bounds.

Implementors return their meta type information.

Functions

Returns the runtime bridge to the types compile-time type information.