diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 67dd411..2ece670 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 --all-features + diff --git a/frame-metadata/Cargo.toml b/frame-metadata/Cargo.toml index 3f95fdd..f127a9c 100644 --- a/frame-metadata/Cargo.toml +++ b/frame-metadata/Cargo.toml @@ -20,6 +20,7 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] } [features] default = ["std", "v14"] +docs = ["scale-info/docs"] v12 = [] v13 = [] v14 = ["scale-info"] diff --git a/frame-metadata/src/v14.rs b/frame-metadata/src/v14.rs index f394f09..0183721 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,48 @@ 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"))] + #[inline] + /// Docs feature is not enabled so this is a no-op. + pub fn with_docs(self, _docs: &[&'static str]) -> Self { + self + } +} + +impl StorageEntryMetadata +where + T: Form, +{ + /// Get the documentation. + pub fn docs(&self) -> &[T::String] { + self.docs.as_slice() + } +} + /// A storage entry modifier. #[derive(Clone, PartialEq, Eq, Encode)] #[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))] @@ -357,7 +399,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 +415,41 @@ 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"))] + #[inline] + /// Docs feature is not enabled so this is a no-op. + pub fn with_docs(self, _docs: &[&'static str]) -> Self { + self + } +} + +impl PalletConstantMetadata +where + T: Form, +{ + /// Get the documentation. + pub fn docs(&self) -> &[T::String] { + self.docs.as_slice() + } +} + /// Metadata about a pallet error. #[derive(Clone, PartialEq, Eq, Encode)] #[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]