From b18eebd235c9ac60b6839fc9bc395f0e46cb8f35 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 19 Jul 2021 15:02:24 +0100 Subject: [PATCH 01/13] Add docs feature --- frame-metadata/Cargo.toml | 2 ++ frame-metadata/src/v14.rs | 75 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/frame-metadata/Cargo.toml b/frame-metadata/Cargo.toml index 3f95fdd..3ce9eb2 100644 --- a/frame-metadata/Cargo.toml +++ b/frame-metadata/Cargo.toml @@ -20,10 +20,12 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] } [features] default = ["std", "v14"] +docs = ["scale-info/docs"] v12 = [] v13 = [] v14 = ["scale-info"] std = [ + "docs", "codec/std", "scale-info/std", "scale-info/serde", diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index f394f09..204b2cb 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -192,7 +192,7 @@ pub struct StorageEntryMetadata { pub modifier: StorageEntryModifier, pub ty: StorageEntryType, pub default: Vec, - pub docs: Vec, + docs: Vec, } impl IntoPortable for StorageEntryMetadata { @@ -209,6 +209,45 @@ impl IntoPortable for StorageEntryMetadata { } } +impl StorageEntryMetadata { + /// Create a new [`StorageEntryMetadata`]. + pub fn new( + name: &'static str, + modifier: StorageEntryModifier, + ty: StorageEntryType, + default: Vec, + ) -> Self { + StorageEntryMetadata { + name, + modifier, + ty, + default, + docs: Vec::new(), + } + } + + #[cfg(feature = "docs")] + /// Set the documentation. + pub fn with_docs(mut self, docs: &[&'static str]) -> Self { + self.docs = docs.to_vec(); + self + } + + #[cfg(not(feature = "docs"))] + /// Docs feature is not enabled so this is a no-op. + #[inline] + pub fn with_docs(mut self, docs: &[&'static str]) -> Self { + self + } +} + +impl StorageEntryMetadata { + /// Get the documentation. + pub fn docs(&self) -> &[String] { + &self.docs + } +} + /// A storage entry modifier. #[derive(Clone, PartialEq, Eq, Encode)] #[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))] @@ -357,7 +396,7 @@ pub struct PalletConstantMetadata { pub name: T::String, pub ty: T::Type, pub value: Vec, - pub docs: Vec, + docs: Vec, } impl IntoPortable for PalletConstantMetadata { @@ -373,6 +412,38 @@ impl IntoPortable for PalletConstantMetadata { } } +impl PalletConstantMetadata { + pub fn new(name: &'static str, ty: MetaType, value: Vec) -> Self { + Self { + name, + ty, + value, + docs: Vec::new(), + } + } + + #[cfg(feature = "docs")] + /// Set the documentation. + pub fn with_docs(mut self, docs: &[&'static str]) -> Self { + self.docs = docs.to_vec(); + self + } + + #[cfg(not(feature = "docs"))] + /// Docs feature is not enabled so this is a no-op. + #[inline] + pub fn with_docs(mut self, docs: &[&'static str]) -> Self { + self + } +} + +impl PalletConstantMetadata { + /// Get the documentation. + pub fn docs(&self) -> &[String] { + &self.docs + } +} + /// Metadata about a pallet error. #[derive(Clone, PartialEq, Eq, Encode)] #[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))] From ea9e8bbb83279cbe3c6854b8a398a492d45f8af1 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 19 Jul 2021 15:08:02 +0100 Subject: [PATCH 02/13] Unused params --- frame-metadata/src/v14.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index 204b2cb..fbf0824 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -236,7 +236,7 @@ impl StorageEntryMetadata { #[cfg(not(feature = "docs"))] /// Docs feature is not enabled so this is a no-op. #[inline] - pub fn with_docs(mut self, docs: &[&'static str]) -> Self { + pub fn with_docs(mut self, _docs: &[&'static str]) -> Self { self } } @@ -432,7 +432,7 @@ impl PalletConstantMetadata { #[cfg(not(feature = "docs"))] /// Docs feature is not enabled so this is a no-op. #[inline] - pub fn with_docs(mut self, docs: &[&'static str]) -> Self { + pub fn with_docs(mut self, _docs: &[&'static str]) -> Self { self } } From 41a9c4b1e9dafd9a39a3adbd23cac24388bfc46d Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 19 Jul 2021 15:10:44 +0100 Subject: [PATCH 03/13] Check all features --- .github/workflows/rust.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 67dd411..6cb650e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -116,10 +116,11 @@ jobs: command: check toolchain: stable args: --manifest-path ./frame-metadata/Cargo.toml --no-default-features --features v14 - - name: Checking all versions + - name: Checking all features uses: actions-rs/cargo@master with: command: check toolchain: stable - args: --manifest-path ./frame-metadata/Cargo.toml --no-default-features --features v12,v13,v14 + args: --manifest-path ./frame-metadata/Cargo.toml --no-default-features --all-features + From 972535c368d1cd044f9f47cc6031b87e800eb244 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 19 Jul 2021 15:11:58 +0100 Subject: [PATCH 04/13] Add String import --- frame-metadata/src/v14.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index fbf0824..05cfedf 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -24,7 +24,10 @@ cfg_if::cfg_if! { use super::RuntimeMetadataPrefixed; use codec::Encode; -use scale_info::prelude::vec::Vec; +use scale_info::prelude::{ + string::String, + vec::Vec, +}; use scale_info::{ form::{Form, MetaForm, PortableForm}, IntoPortable, MetaType, PortableRegistry, Registry, From c60614aeab20507ba1152f06f9bd8949385a67e8 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 19 Jul 2021 15:13:29 +0100 Subject: [PATCH 05/13] Fmt --- frame-metadata/src/v14.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index 05cfedf..df87894 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -24,10 +24,7 @@ cfg_if::cfg_if! { use super::RuntimeMetadataPrefixed; use codec::Encode; -use scale_info::prelude::{ - string::String, - vec::Vec, -}; +use scale_info::prelude::{string::String, vec::Vec}; use scale_info::{ form::{Form, MetaForm, PortableForm}, IntoPortable, MetaType, PortableRegistry, Registry, From cc6e9703da31963b9b0022090ebe9128d815cbb3 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 19 Jul 2021 15:21:00 +0100 Subject: [PATCH 06/13] Fix warns and errors --- frame-metadata/src/v14.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index df87894..6e25a4a 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -24,7 +24,7 @@ cfg_if::cfg_if! { use super::RuntimeMetadataPrefixed; use codec::Encode; -use scale_info::prelude::{string::String, vec::Vec}; +use scale_info::prelude::vec::Vec; use scale_info::{ form::{Form, MetaForm, PortableForm}, IntoPortable, MetaType, PortableRegistry, Registry, @@ -236,15 +236,15 @@ impl StorageEntryMetadata { #[cfg(not(feature = "docs"))] /// Docs feature is not enabled so this is a no-op. #[inline] - pub fn with_docs(mut self, _docs: &[&'static str]) -> Self { + pub fn with_docs(self, _docs: &[&'static str]) -> Self { self } } impl StorageEntryMetadata { /// Get the documentation. - pub fn docs(&self) -> &[String] { - &self.docs + pub fn docs(&self) -> &[&str] { + self.docs.as_slice() } } @@ -432,14 +432,14 @@ impl PalletConstantMetadata { #[cfg(not(feature = "docs"))] /// Docs feature is not enabled so this is a no-op. #[inline] - pub fn with_docs(mut self, _docs: &[&'static str]) -> Self { + pub fn with_docs(self, _docs: &[&'static str]) -> Self { self } } impl PalletConstantMetadata { /// Get the documentation. - pub fn docs(&self) -> &[String] { + pub fn docs(&self) -> &[&str] { &self.docs } } From c21dbe0c75364c92d334c94d03152a0c93bb60a5 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 19 Jul 2021 15:34:16 +0100 Subject: [PATCH 07/13] Use PortableForm::String --- frame-metadata/src/v14.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index 6e25a4a..eda0deb 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -243,7 +243,7 @@ impl StorageEntryMetadata { impl StorageEntryMetadata { /// Get the documentation. - pub fn docs(&self) -> &[&str] { + pub fn docs(&self) -> &[::String] { self.docs.as_slice() } } @@ -439,8 +439,8 @@ impl PalletConstantMetadata { impl PalletConstantMetadata { /// Get the documentation. - pub fn docs(&self) -> &[&str] { - &self.docs + pub fn docs(&self) -> &[::String] { + self.docs.as_slice() } } From 0e7ac848b551e8b1d1e5271d01a47b5ff6bbae32 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 19 Jul 2021 15:40:50 +0100 Subject: [PATCH 08/13] Really, all features --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6cb650e..2ece670 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -121,6 +121,6 @@ jobs: with: command: check toolchain: stable - args: --manifest-path ./frame-metadata/Cargo.toml --no-default-features --all-features + args: --manifest-path ./frame-metadata/Cargo.toml --all-features From 419e09b4cdea84a299388efbabc7e27a72f66011 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 21 Jul 2021 08:36:31 +0100 Subject: [PATCH 09/13] Use Form String for docs getter --- frame-metadata/src/v14.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index eda0deb..82e14ee 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -241,9 +241,12 @@ impl StorageEntryMetadata { } } -impl StorageEntryMetadata { +impl StorageEntryMetadata +where + T: Form +{ /// Get the documentation. - pub fn docs(&self) -> &[::String] { + pub fn docs(&self) -> &[T::String] { self.docs.as_slice() } } @@ -437,9 +440,12 @@ impl PalletConstantMetadata { } } -impl PalletConstantMetadata { +impl PalletConstantMetadata +where + T: Form +{ /// Get the documentation. - pub fn docs(&self) -> &[::String] { + pub fn docs(&self) -> &[T::String] { self.docs.as_slice() } } From a4b64c1690e98ffef09e225e3115ae9b44b7f16d Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 21 Jul 2021 08:41:09 +0100 Subject: [PATCH 10/13] Fmt --- frame-metadata/src/v14.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index 82e14ee..10701f9 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -243,7 +243,7 @@ impl StorageEntryMetadata { impl StorageEntryMetadata where - T: Form + T: Form, { /// Get the documentation. pub fn docs(&self) -> &[T::String] { @@ -442,7 +442,7 @@ impl PalletConstantMetadata { impl PalletConstantMetadata where - T: Form + T: Form, { /// Get the documentation. pub fn docs(&self) -> &[T::String] { From d53ee6787f931cee2c9787b83f2780f8e56285f8 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 21 Jul 2021 08:43:44 +0100 Subject: [PATCH 11/13] Missing impl T --- frame-metadata/src/v14.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index 10701f9..617ad23 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -440,7 +440,7 @@ impl PalletConstantMetadata { } } -impl PalletConstantMetadata +impl PalletConstantMetadata where T: Form, { From 2e1b1c80b428622d9d9f142068865a1502d62cda Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 21 Jul 2021 10:30:39 +0100 Subject: [PATCH 12/13] Docs feature not enabled by default --- frame-metadata/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/frame-metadata/Cargo.toml b/frame-metadata/Cargo.toml index 3ce9eb2..f127a9c 100644 --- a/frame-metadata/Cargo.toml +++ b/frame-metadata/Cargo.toml @@ -25,7 +25,6 @@ v12 = [] v13 = [] v14 = ["scale-info"] std = [ - "docs", "codec/std", "scale-info/std", "scale-info/serde", From 2d560b342dbff13ce78b2021827db04b5eca22d6 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 21 Jul 2021 10:31:19 +0100 Subject: [PATCH 13/13] Comment ordering --- frame-metadata/src/v14.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index 617ad23..0183721 100644 --- a/frame-metadata/src/v14.rs +++ b/frame-metadata/src/v14.rs @@ -234,8 +234,8 @@ impl StorageEntryMetadata { } #[cfg(not(feature = "docs"))] - /// Docs feature is not enabled so this is a no-op. #[inline] + /// Docs feature is not enabled so this is a no-op. pub fn with_docs(self, _docs: &[&'static str]) -> Self { self } @@ -433,8 +433,8 @@ impl PalletConstantMetadata { } #[cfg(not(feature = "docs"))] - /// Docs feature is not enabled so this is a no-op. #[inline] + /// Docs feature is not enabled so this is a no-op. pub fn with_docs(self, _docs: &[&'static str]) -> Self { self }