Module borsh::schema

source ·
Expand description

Module is available if borsh is built with features = ["unstable__schema"].

Since Borsh is not a self-descriptive format we have a way to describe types serialized with Borsh so that we can deserialize serialized blobs without having Rust types available. Additionally, this can be used to serialize content provided in a different format, e.g. JSON object {"user": "alice", "message": "Message"} can be serialized by JS code into Borsh format such that it can be deserialized into struct UserMessage {user: String, message: String} on Rust side.

The important components are: BorshSchema trait, Definition and Declaration types, and BorshSchemaContainer struct.

  • BorshSchema trait allows any type that implements it to be self-descriptive, i.e. generate it’s own schema;
  • Declaration is used to describe the type identifier, e.g. HashMap<u64, String>;
  • Definition is used to describe the structure of the type;
  • BorshSchemaContainer is used to store all declarations and definitions that are needed to work with a single type.

Modules§

  • Module is available if borsh is built with features = ["std"] or features = ["hashbrown"].
  • Module is available if borsh is built with features = ["rc"].

Structs§

Enums§

  • The type that we use to represent the definition of the Borsh type. Description of data encoding on the wire.
  • The collection representing the fields of a struct.
  • Possible error when validating a BorshSchemaContainer, generated for some type T, for violation of any well-known rules with respect to borsh serialization.
  • Possible error when calculating theoretical maximum size of encoded type T.

Traits§

  • The declaration and the definition of the type that can be used to (de)serialize Borsh without the Rust type that produced it.

Functions§

  • Helper method to add a single type definition to the map.

Type Aliases§

  • The type that we use to represent the declaration of the Borsh type.
  • The type that we use for value of discriminant.
  • The name of the field in the struct (can be used to convert JSON to Borsh using the schema).
  • The type that we use for the name of the variant.