Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.3.0 #170

Merged
merged 10 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.3.0] - 2022-10.27

Implement the missing pieces for constructing `PortableRegistry` dynamically at runtime. This allows languages where static rust types are not available to use it.

## [2.2.0] - 2022-09-14

The minimum Rust version is bumped to 1.60.0 in this release owing to using weak dependency crate features. Otherwise there are no breaking changes.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scale-info"
version = "2.2.0"
version = "2.3.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
rust-version = "1.60.0"
Expand All @@ -17,7 +17,7 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
[dependencies]
bitvec = { version = "1", default-features = false, features = ["alloc"], optional = true }
cfg-if = "1.0"
scale-info-derive = { version = "2.2.0", path = "derive", default-features = false, optional = true }
scale-info-derive = { version = "2.3.0", path = "derive", default-features = false, optional = true }
serde = { version = "1", default-features = false, optional = true, features = ["derive", "alloc"] }
derive_more = { version = "0.99.1", default-features = false, features = ["from"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scale-info-derive"
version = "2.2.0"
version = "2.3.0"
authors = [
"Parity Technologies <admin@parity.io>",
"Centrality Developers <support@centrality.ai>",
Expand Down
2 changes: 1 addition & 1 deletion derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl TypeInfoImpl {

if !docs.is_empty() {
Some(quote! {
.#docs_builder_fn([ #( #docs ),* ])
.#docs_builder_fn(&[ #( #docs ),* ])
})
} else {
None
Expand Down
91 changes: 53 additions & 38 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,33 +214,38 @@ impl<F: Form, S> TypeBuilder<F, S> {
self.type_params = type_params.into_iter().collect();
self
}
}

impl<S> TypeBuilder<PortableForm, S> {
#[cfg(feature = "docs")]
/// Set the type documentation
pub fn docs<I>(mut self, docs: I) -> Self
/// Set the type documentation (for types in portable form).
pub fn docs_portable<I>(mut self, docs: I) -> Self
where
I: IntoIterator<Item = F::String>,
I: IntoIterator<Item = <PortableForm as Form>::String>,
{
self.docs = docs.into_iter().collect();
self
}
}

impl<S> TypeBuilder<MetaForm, S> {
#[cfg(feature = "docs")]
/// Set the type documentation
pub fn docs(mut self, docs: &[&'static str]) -> Self {
self.docs = docs.to_vec();
self
}

#[cfg(not(feature = "docs"))]
#[inline]
/// Doc capture is not enabled via the "docs" feature so this is a no-op.
pub fn docs<I>(self, _docs: I) -> Self
where
I: IntoIterator<Item = F::String>,
{
pub fn docs(self, _docs: &'static [&'static str]) -> Self {
self
}

/// Set the type documentation, always captured even if the "docs" feature is not enabled.
pub fn docs_always<I>(mut self, docs: I) -> Self
where
I: IntoIterator<Item = F::String>,
{
self.docs = docs.into_iter().collect();
pub fn docs_always(mut self, docs: &[&'static str]) -> Self {
self.docs = docs.to_vec();
self
}
}
Expand Down Expand Up @@ -503,43 +508,48 @@ impl<F: Form, N, T> FieldBuilder<F, N, T> {
marker: PhantomData,
}
}
}

impl<N, T> FieldBuilder<PortableForm, N, T> {
#[cfg(feature = "docs")]
/// Initialize the documentation of a field (optional).
pub fn docs<I>(self, docs: I) -> FieldBuilder<F, N, T>
/// Initialize the documentation of a field (for types in portable form, optional).
pub fn docs_portable<I>(mut self, docs: I) -> Self
ascjones marked this conversation as resolved.
Show resolved Hide resolved
where
I: IntoIterator<Item = F::String>,
I: IntoIterator<Item = <PortableForm as Form>::String>,
{
self.docs = docs.into_iter().collect();
self
}
}

impl<N, T> FieldBuilder<MetaForm, N, T> {
#[cfg(feature = "docs")]
/// Initialize the documentation of a field (optional).
pub fn docs(self, docs: &'static [&'static str]) -> Self {
FieldBuilder {
name: self.name,
ty: self.ty,
type_name: self.type_name,
docs: docs.into_iter().collect(),
docs: docs.to_vec(),
marker: PhantomData,
}
}

#[cfg(not(feature = "docs"))]
#[inline]
/// Doc capture is not enabled via the "docs" feature so this is a no-op.
pub fn docs<I>(self, _docs: I) -> FieldBuilder<F, N, T>
where
I: IntoIterator<Item = F::String>,
{
pub fn docs(self, _docs: &'static [&'static str]) -> Self {
self
}

/// Initialize the documentation of a field, always captured even if the "docs" feature is not
/// enabled.
pub fn docs_always<I>(self, docs: I) -> Self
where
I: IntoIterator<Item = F::String>,
{
pub fn docs_always(self, docs: &'static [&'static str]) -> Self {
FieldBuilder {
name: self.name,
ty: self.ty,
type_name: self.type_name,
docs: docs.into_iter().collect(),
docs: docs.to_vec(),
marker: PhantomData,
}
}
Expand Down Expand Up @@ -652,34 +662,39 @@ impl<F: Form, S> VariantBuilder<F, S> {
self.fields = fields_builder.finalize();
self
}
}

impl<S> VariantBuilder<PortableForm, S> {
#[cfg(feature = "docs")]
/// Initialize the variant's documentation.
pub fn docs<I>(mut self, docs: I) -> Self
/// Initialize the variant's documentation (for types in portable form).
pub fn docs_portable<I>(mut self, docs: I) -> Self
where
I: IntoIterator<Item = F::String>,
I: IntoIterator<Item = <PortableForm as Form>::String>,
{
self.docs = docs.into_iter().map(Into::into).collect();
self.docs = docs.into_iter().collect();
self
}
}

impl<S> VariantBuilder<MetaForm, S> {
#[cfg(feature = "docs")]
/// Initialize the variant's documentation.
pub fn docs(mut self, docs: &[&'static str]) -> Self {
self.docs = docs.to_vec();
self
}

#[cfg(not(feature = "docs"))]
#[inline]
/// Doc capture is not enabled via the "docs" feature so this is a no-op.
pub fn docs<I>(self, _docs: I) -> Self
where
I: IntoIterator<Item = F::String>,
{
pub fn docs(self, _docs: &[&'static str]) -> Self {
self
}

/// Initialize the variant's documentation, always captured even if the "docs" feature is not
/// enabled.
pub fn docs_always<I>(mut self, docs: I) -> Self
where
I: IntoIterator<Item = F::String>,
{
self.docs = docs.into_iter().collect();
pub fn docs_always(mut self, docs: &[&'static str]) -> Self {
self.docs = docs.to_vec();
self
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl<T> TypeInfo for PhantomData<T> {
// Fields of this type should be filtered out and never appear in the type graph.
Type::builder()
.path(Path::prelude("PhantomData"))
.docs(["PhantomData placeholder, this type should be filtered out"])
.docs(&["PhantomData placeholder, this type should be filtered out"])
.composite(Fields::unit())
}
}
Expand Down
21 changes: 16 additions & 5 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
//! namespaces. The normal Rust namespace of a type is used, except for the Rust
//! prelude types that live in the so-called root namespace which is empty.

use crate::prelude::{
any::TypeId,
collections::BTreeMap,
fmt::Debug,
vec::Vec,
use crate::{
form::Form,
prelude::{
any::TypeId,
collections::BTreeMap,
fmt::Debug,
vec::Vec,
},
};

use crate::{
Expand All @@ -49,6 +52,14 @@ pub trait IntoPortable {
fn into_portable(self, registry: &mut Registry) -> Self::Output;
}

impl IntoPortable for &'static str {
type Output = <PortableForm as Form>::String;

fn into_portable(self, _registry: &mut Registry) -> Self::Output {
self.into()
}
}

/// The registry for space-efficient storage of type identifiers and
/// definitions.
///
Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn phantom_data() {
PhantomData<i32>,
Type::builder()
.path(Path::prelude("PhantomData"))
.docs(["PhantomData placeholder, this type should be filtered out"])
.docs(&["PhantomData placeholder, this type should be filtered out"])
.composite(Fields::unit())
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/ty/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Path<MetaForm> {
/// - If the supplied ident is not a valid Rust identifier
pub(crate) fn prelude(ident: <MetaForm as Form>::String) -> Self {
Self::from_segments([ident])
.unwrap_or_else(|_| panic!("{:?} is not a valid Rust identifier", ident))
.unwrap_or_else(|_| panic!("{ident:?} is not a valid Rust identifier"))
}
}

Expand Down