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

serde feature added #745

Merged
merged 9 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions bounded-collections/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: If we are following semver here, should this technically be a minor version bump? Since we are adding functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks like we weren't very strict about semver in the past, but good to start now. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, since we're still at 0.y.z we might have been following the common scheme where y is reserved for breaking changes.

The spec recommends always bumping y on new releases when x=0, but probably we shouldn't change the strategy we were already following. Maybe we should revert? 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are fine for me. But following previous strategy makes sense. I'll revert.


## [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`).

Expand Down
10 changes: 6 additions & 4 deletions bounded-collections/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bounded-collections"
version = "0.1.5"
version = "0.1.6"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/paritytech/parity-common"
Expand All @@ -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 }
Expand All @@ -19,10 +19,12 @@ serde_json = "1.0.41"

[features]
default = ["std"]
serde = [
"dep:serde"
]
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
std = [
"log/std",
"codec/std",
"scale-info/std",
"serde",
"serde/derive",
"serde/std",
]
10 changes: 5 additions & 5 deletions bounded-collections/src/bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,18 +40,18 @@ 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<T, S>(pub(super) Vec<T>, #[cfg_attr(feature = "std", serde(skip_serializing))] PhantomData<S>);
pub struct BoundedVec<T, S>(pub(super) Vec<T>, #[cfg_attr(feature = "serde", serde(skip_serializing))] PhantomData<S>);

/// Create an object through truncation.
pub trait TruncateFrom<T> {
/// Create an object through truncation.
fn truncate_from(unbound: T) -> Self;
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<'de, T, S: Get<u32>> Deserialize<'de> for BoundedVec<T, S>
where
T: Deserialize<'de>,
Expand All @@ -68,7 +68,7 @@ where
{
type Value = Vec<T>;

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")
}

Expand Down
10 changes: 5 additions & 5 deletions bounded-collections/src/weak_bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,15 +40,15 @@ 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<T, S>(
pub(super) Vec<T>,
#[cfg_attr(feature = "std", serde(skip_serializing))] PhantomData<S>,
#[cfg_attr(feature = "serde", serde(skip_serializing))] PhantomData<S>,
);

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<'de, T, S: Get<u32>> Deserialize<'de> for WeakBoundedVec<T, S>
where
T: Deserialize<'de>,
Expand All @@ -65,7 +65,7 @@ where
{
type Value = Vec<T>;

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")
}

Expand Down