From 2ffb9b8a8d43f8a81c3a9eba5dae5af5bb3f96f6 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 28 Apr 2023 14:08:26 +0200 Subject: [PATCH 1/8] serde feature added Support for serde derivations in no_std. Part of: https://github.com/paritytech/substrate/issues/12994 --- bounded-collections/Cargo.toml | 10 ++++++---- bounded-collections/src/bounded_vec.rs | 10 +++++----- bounded-collections/src/weak_bounded_vec.rs | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/bounded-collections/Cargo.toml b/bounded-collections/Cargo.toml index e5ae0780..f26e70b9 100644 --- a/bounded-collections/Cargo.toml +++ b/bounded-collections/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bounded-collections" -version = "0.1.5" +version = "0.1.6" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" @@ -9,7 +9,7 @@ edition = "2021" rust-version = "1.60.0" [dependencies] -serde = { version = "1.0.101", default-features = false, optional = true } +serde = { version = "1.0.101", default-features = false, optional = true, features=["alloc", "derive"] } codec = { version = "3.3.0", default-features = false, features = ["max-encoded-len"], package = "parity-scale-codec" } scale-info = { version = ">=1.0, <3", features = ["derive"], default-features = false } log = { version = "0.4.17", default-features = false } @@ -19,10 +19,12 @@ serde_json = "1.0.41" [features] default = ["std"] +serde = [ + "dep:serde" +] std = [ "log/std", "codec/std", "scale-info/std", - "serde", - "serde/derive", + "serde/std", ] diff --git a/bounded-collections/src/bounded_vec.rs b/bounded-collections/src/bounded_vec.rs index 33a192fe..fd617ee7 100644 --- a/bounded-collections/src/bounded_vec.rs +++ b/bounded-collections/src/bounded_vec.rs @@ -27,7 +27,7 @@ use core::{ ops::{Deref, Index, IndexMut, RangeBounds}, slice::SliceIndex, }; -#[cfg(feature = "std")] +#[cfg(feature = "serde")] use serde::{ de::{Error, SeqAccess, Visitor}, Deserialize, Deserializer, Serialize, @@ -40,10 +40,10 @@ use serde::{ /// /// As the name suggests, the length of the queue is always bounded. All internal operations ensure /// this bound is respected. -#[cfg_attr(feature = "std", derive(Serialize), serde(transparent))] +#[cfg_attr(feature = "serde", derive(Serialize), serde(transparent))] #[derive(Encode, scale_info::TypeInfo)] #[scale_info(skip_type_params(S))] -pub struct BoundedVec(pub(super) Vec, #[cfg_attr(feature = "std", serde(skip_serializing))] PhantomData); +pub struct BoundedVec(pub(super) Vec, #[cfg_attr(feature = "serde", serde(skip_serializing))] PhantomData); /// Create an object through truncation. pub trait TruncateFrom { @@ -51,7 +51,7 @@ pub trait TruncateFrom { fn truncate_from(unbound: T) -> Self; } -#[cfg(feature = "std")] +#[cfg(feature = "serde")] impl<'de, T, S: Get> Deserialize<'de> for BoundedVec where T: Deserialize<'de>, @@ -68,7 +68,7 @@ where { type Value = Vec; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut alloc::fmt::Formatter) -> alloc::fmt::Result { formatter.write_str("a sequence") } diff --git a/bounded-collections/src/weak_bounded_vec.rs b/bounded-collections/src/weak_bounded_vec.rs index cb711d76..974a1aa5 100644 --- a/bounded-collections/src/weak_bounded_vec.rs +++ b/bounded-collections/src/weak_bounded_vec.rs @@ -27,7 +27,7 @@ use core::{ ops::{Deref, Index, IndexMut}, slice::SliceIndex, }; -#[cfg(feature = "std")] +#[cfg(feature = "serde")] use serde::{ de::{Error, SeqAccess, Visitor}, Deserialize, Deserializer, Serialize, @@ -40,7 +40,7 @@ use serde::{ /// /// The length of the vec is not strictly bounded. Decoding a vec with more element that the bound /// is accepted, and some method allow to bypass the restriction with warnings. -#[cfg_attr(feature = "std", derive(Serialize), serde(transparent))] +#[cfg_attr(feature = "serde", derive(Serialize), serde(transparent))] #[derive(Encode, scale_info::TypeInfo)] #[scale_info(skip_type_params(S))] pub struct WeakBoundedVec( @@ -65,7 +65,7 @@ where { type Value = Vec; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut alloc::fmt::Formatter) -> alloc::fmt::Result { formatter.write_str("a sequence") } From 443d175354bf2aabd214bccd932349672493ef39 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 28 Apr 2023 14:19:24 +0200 Subject: [PATCH 2/8] bump serde to 1.0.160 + fixes --- bounded-collections/Cargo.toml | 2 +- bounded-collections/src/weak_bounded_vec.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bounded-collections/Cargo.toml b/bounded-collections/Cargo.toml index f26e70b9..1313569a 100644 --- a/bounded-collections/Cargo.toml +++ b/bounded-collections/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" rust-version = "1.60.0" [dependencies] -serde = { version = "1.0.101", default-features = false, optional = true, features=["alloc", "derive"] } +serde = { version = "1.0.160", default-features = false, optional = true, features=["alloc", "derive"] } codec = { version = "3.3.0", default-features = false, features = ["max-encoded-len"], package = "parity-scale-codec" } scale-info = { version = ">=1.0, <3", features = ["derive"], default-features = false } log = { version = "0.4.17", default-features = false } diff --git a/bounded-collections/src/weak_bounded_vec.rs b/bounded-collections/src/weak_bounded_vec.rs index 974a1aa5..de5fa712 100644 --- a/bounded-collections/src/weak_bounded_vec.rs +++ b/bounded-collections/src/weak_bounded_vec.rs @@ -45,10 +45,10 @@ use serde::{ #[scale_info(skip_type_params(S))] pub struct WeakBoundedVec( pub(super) Vec, - #[cfg_attr(feature = "std", serde(skip_serializing))] PhantomData, + #[cfg_attr(feature = "serde", serde(skip_serializing))] PhantomData, ); -#[cfg(feature = "std")] +#[cfg(feature = "serde")] impl<'de, T, S: Get> Deserialize<'de> for WeakBoundedVec where T: Deserialize<'de>, From b15dde346779803b3e7743ecc79226de7ae546e8 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 5 May 2023 12:17:24 +0200 Subject: [PATCH 3/8] CI tests for serde, CHANGELOG updated --- .github/workflows/ci.yml | 6 ++++++ bounded-collections/CHANGELOG.md | 3 +++ bounded-collections/Cargo.toml | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6c95932..f9d16c8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,6 +104,12 @@ jobs: command: test args: -p bounded-collections --no-default-features + - name: Test bounded-collections no_std,serde + uses: actions-rs/cargo@v1 + with: + command: test + args: -p bounded-collections --no-default-features --features='serde' + - name: Test bounded-collections all-features uses: actions-rs/cargo@v1 with: diff --git a/bounded-collections/CHANGELOG.md b/bounded-collections/CHANGELOG.md index 8198520b..67b73ccf 100644 --- a/bounded-collections/CHANGELOG.md +++ b/bounded-collections/CHANGELOG.md @@ -4,6 +4,9 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ +## [0.1.6] - 2023-05-05 +- Added `serde` feature, which can be enabled for no `std` deployments. + ## [0.1.5] - 2023-02-13 - Fixed `Hash` impl (previously it could not be used in practice, because the size bound was required to also implement `Hash`). diff --git a/bounded-collections/Cargo.toml b/bounded-collections/Cargo.toml index 1313569a..f26e70b9 100644 --- a/bounded-collections/Cargo.toml +++ b/bounded-collections/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" rust-version = "1.60.0" [dependencies] -serde = { version = "1.0.160", default-features = false, optional = true, features=["alloc", "derive"] } +serde = { version = "1.0.101", default-features = false, optional = true, features=["alloc", "derive"] } codec = { version = "3.3.0", default-features = false, features = ["max-encoded-len"], package = "parity-scale-codec" } scale-info = { version = ">=1.0, <3", features = ["derive"], default-features = false } log = { version = "0.4.17", default-features = false } From 7bbf8760378a4d540afc3d56128bd6448267f6f7 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 5 May 2023 12:21:13 +0200 Subject: [PATCH 4/8] version changed to 0.1.7 --- bounded-collections/CHANGELOG.md | 1 - bounded-collections/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bounded-collections/CHANGELOG.md b/bounded-collections/CHANGELOG.md index 9618c814..7e1c40c5 100644 --- a/bounded-collections/CHANGELOG.md +++ b/bounded-collections/CHANGELOG.md @@ -11,7 +11,6 @@ The format is based on [Keep a Changelog]. - Added `Clone` and `Default` derive to the `impl_const_get!` macro and thereby all `Const*` types. - Fixed `Debug` impl for `impl_const_get!` and all `Const*` types to also print the value and not just the type name. - ## [0.1.5] - 2023-02-13 - Fixed `Hash` impl (previously it could not be used in practice, because the size bound was required to also implement `Hash`). diff --git a/bounded-collections/Cargo.toml b/bounded-collections/Cargo.toml index f26e70b9..ccefdff9 100644 --- a/bounded-collections/Cargo.toml +++ b/bounded-collections/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bounded-collections" -version = "0.1.6" +version = "0.1.7" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" From 02f09de224499ab9b5dc73c6ef324660f9b5c097 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 5 May 2023 12:27:50 +0200 Subject: [PATCH 5/8] version 0.2.0 --- bounded-collections/CHANGELOG.md | 2 +- bounded-collections/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bounded-collections/CHANGELOG.md b/bounded-collections/CHANGELOG.md index 7e1c40c5..ef8b53fb 100644 --- a/bounded-collections/CHANGELOG.md +++ b/bounded-collections/CHANGELOG.md @@ -4,7 +4,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ -## [0.1.7] - 2023-05-05 +## [0.2.0] - 2023-05-05 - Added `serde` feature, which can be enabled for no `std` deployments. ## [0.1.6] - 2023-04-27 diff --git a/bounded-collections/Cargo.toml b/bounded-collections/Cargo.toml index ccefdff9..02039708 100644 --- a/bounded-collections/Cargo.toml +++ b/bounded-collections/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bounded-collections" -version = "0.1.7" +version = "0.2.0" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" From da29216e0bb22c63b913623b719a00feefc87e93 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 5 May 2023 12:38:14 +0200 Subject: [PATCH 6/8] fix for ci command --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9d16c8c..571ae99c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,7 +108,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: test - args: -p bounded-collections --no-default-features --features='serde' + args: -p bounded-collections --no-default-features --features=serde - name: Test bounded-collections all-features uses: actions-rs/cargo@v1 From b460ea89be60a6754a4b74876498d812c7d0f76e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 5 May 2023 13:04:37 +0200 Subject: [PATCH 7/8] Revert "version 0.2.0" This reverts commit 02f09de224499ab9b5dc73c6ef324660f9b5c097. --- bounded-collections/CHANGELOG.md | 2 +- bounded-collections/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bounded-collections/CHANGELOG.md b/bounded-collections/CHANGELOG.md index ef8b53fb..7e1c40c5 100644 --- a/bounded-collections/CHANGELOG.md +++ b/bounded-collections/CHANGELOG.md @@ -4,7 +4,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ -## [0.2.0] - 2023-05-05 +## [0.1.7] - 2023-05-05 - Added `serde` feature, which can be enabled for no `std` deployments. ## [0.1.6] - 2023-04-27 diff --git a/bounded-collections/Cargo.toml b/bounded-collections/Cargo.toml index 02039708..ccefdff9 100644 --- a/bounded-collections/Cargo.toml +++ b/bounded-collections/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bounded-collections" -version = "0.2.0" +version = "0.1.7" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" From bf7484fc1d94d8bc1442e75d1cb7354f1b2cb7bd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 5 May 2023 13:56:02 +0200 Subject: [PATCH 8/8] Update bounded-collections/Cargo.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- bounded-collections/Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/bounded-collections/Cargo.toml b/bounded-collections/Cargo.toml index ccefdff9..98b9f4c3 100644 --- a/bounded-collections/Cargo.toml +++ b/bounded-collections/Cargo.toml @@ -19,9 +19,6 @@ serde_json = "1.0.41" [features] default = ["std"] -serde = [ - "dep:serde" -] std = [ "log/std", "codec/std",