rain_metadata/
lib.rs

1#![doc(
2    html_logo_url = "https://raw.githubusercontent.com/rainlanguage/rainlang-vscode/master/docs/images/rain-logo-icon.svg",
3    html_favicon_url = "https://raw.githubusercontent.com/rainlanguage/rainlang-vscode/master/docs/images/rain-logo-icon.svg"
4)]
5//! # Rain Metadata Tooling
6//!
7//! A library that provides all the toolings and utilities in order to work with RainLanguage metadata.
8//! Dotrain LSP/compiler, Rain Orderbook, etc are a few examples to mention that use this library under the hood.
9//!
10//! Also provides CLI app (executable binary) to generate desireable Rain cbor encoded metadata based on [Metadata Specs](https://github.com/rainprotocol/specs/blob/main/metadata-v1.md)
11//! which for example is used in Rain deployment CI.
12//!
13//! ## Features
14//!
15//! `cli` and `json-schema` features are default however, in most cases non of the features are needed for using the lib
16//! crate, so they can be disabled by using `default-features = false`, just be aware that `cli` feature is required for
17//! building the binary.
18//!
19//! - `cli`: A [mod@clap] based CLI app module for functionalities of this library, this feature
20//! has [mod@tokio] dependency with features enabled that are compatible for `wasm` family target builds,
21//! Enabling this feature will also enable `json-schema` feature.
22//! This feature is required for building the binary crate.
23//! - `json-schema`: Enables implementation of [Json Schema](schemars::JsonSchema) for different [types] of Rain meta.
24//! - `tokio-full`: Installs [mod@tokio] with full features which is a dependency of `cli` feature, this
25//! allows for multi-threading of the CLI app (binary), however it results in erroneous builds for `wasm` target family
26//! as explained in [tokio docs](https://docs.rs/tokio/latest/tokio/#wasm-support).this feature is only effective for
27//! binary crate and using it for lib crate just installs a [mod@tokio] with full feature as a dependency as the entire
28//! lib crate doesn't depend on [mod@tokio]. This is because [mod@tokio] is only used as a runtime for binray crate.
29//!
30//! ## Example
31//! ```ignore
32//! use rain_meta::{*, types::authoring::v1::AuthoringMeta};
33//!
34//! let authoring_meta_content = r#"[
35//!   {
36//!      "word": "stack",
37//!      "description": "Copies an existing value from the stack.",
38//!      "operandParserOffset": 16
39//!   },
40//!   {
41//!      "word": "constant",
42//!      "description": "Copies a constant value onto the stack.",
43//!      "operandParserOffset": 16
44//!   }
45//! ]"#;
46//! let authoring_meta: AuthoringMeta = serde_json::from_str(authoring_meta_content).unwrap();
47//!
48//! // abi encode the authoring meta with performing validation
49//! let authoring_meta_abi_encoded = authoring_meta.abi_encode_validate().unwrap();
50//!
51//! // Constructing a RainMeta item (cbor map)
52//! let meta_map = RainMetaDocumentV1Item {
53//!   payload: serde_bytes::ByteBuf::from(authoring_meta_abi_encoded),
54//!   magic: KnownMagic::AuthoringMetaV1,
55//!   content_type: ContentType::Cbor,
56//!   content_encoding: ContentEncoding::None,
57//!   content_language: ContentLanguage::None,
58//! };
59//!
60//! // cbor encode the meta item
61//! let cbor_encoded = meta_map.cbor_encode().unwrap();
62//!
63//! // decode the data back
64//! let cbor_decoded_vec = RainMetaDocumentV1Item::cbor_decode(&cbor_encoded).unwrap();
65//!
66//! // unpack the payload into AuthoringMeta
67//! let unpacked_payload: AuthoringMeta = cbor_decoded_vec[0].clone().unpack_into().unwrap();
68//! ```
69
70pub(crate) mod solc;
71pub mod meta;
72pub mod error;
73pub(crate) mod subgraph;
74
75#[cfg(feature = "cli")]
76pub mod cli;
77
78// re-export main types and functionalities
79pub use solc::*;
80pub use meta::*;
81pub use error::*;
82pub use subgraph::*;