subxt_core/metadata/mod.rs
1// Copyright 2019-2024 Parity Technologies (UK) Ltd.
2// This file is dual-licensed as Apache-2.0 or GPL-3.0.
3// see LICENSE for license details.
4
5//! A [`Metadata`] type, which is used through this crate.
6//!
7//! This can be decoded from the bytes handed back from a node when asking for metadata.
8//!
9//! # Examples
10//!
11//! ```rust
12//! use subxt_core::metadata;
13//!
14//! // We need to fetch the bytes from somewhere, and then we can decode them:
15//! let metadata_bytes = include_bytes!("../../../artifacts/polkadot_metadata_small.scale");
16//! let metadata = metadata::decode_from(&metadata_bytes[..]).unwrap();
17//! ```
18
19mod decode_encode_traits;
20mod metadata_type;
21
22use codec::Decode;
23
24pub use decode_encode_traits::{DecodeWithMetadata, EncodeWithMetadata};
25pub use metadata_type::Metadata;
26
27/// Attempt to decode some bytes into [`Metadata`], returning an error
28/// if decoding fails.
29///
30/// This is a shortcut for importing [`codec::Decode`] and using the
31/// implementation of that on [`Metadata`].
32pub fn decode_from(bytes: &[u8]) -> Result<Metadata, codec::Error> {
33 Metadata::decode(&mut &*bytes)
34}