[][src]Crate scale_info

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

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 form definitions.

interner

Interning data structure and associated symbol definitions.

prelude

Exports from std, core and alloc crates.

Macros

tuple_meta_type

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

Structs

Field

A field of a struct-like data type.

MetaType

A metatype abstraction.

Path

Represents the path of a type definition.

PortableRegistry

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

Registry

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

Type

A Type definition with optional metadata.

TypeDefArray

An array type.

TypeDefComposite

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

TypeDefPhantom

A type describing a PhantomData<T> type.

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

IntoPortable

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

TypeInfo

Implementors return their meta type information.

Functions

meta_type

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