Skip to content

Commit

Permalink
Ensure bounded-collections compiles under no_std (#712)
Browse files Browse the repository at this point in the history
* Ensure bounded-collections compiles under no_std

* Add README.md

* Fixes

* Add CHANGELOG.md to bounded-collections

* Add CI check for bounded-collections
  • Loading branch information
KiChjang authored Jan 27, 2023
1 parent 0e53fd9 commit b9123ad
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 8 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ jobs:
command: test
args: -p ethbloom --all-features

- name: Test bounded-collections no_std
uses: actions-rs/cargo@v1
with:
command: test
args: -p bounded-collections --no-default-features

- name: Test bounded-collections all-features
uses: actions-rs/cargo@v1
with:
command: test
args: -p bounded-collections --all-features

- name: Test uint on bigendian
if: runner.os == 'Linux'
uses: actions-rs/cargo@v1
Expand Down
16 changes: 16 additions & 0 deletions bounded-collections/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

The format is based on [Keep a Changelog].

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [0.1.2] - 2023-01-27
- Ensured `bounded-collections` crate compiles under `no_std`. [#712](https://github.com/paritytech/parity-common/pull/712)

## [0.1.1] - 2023-01-26
- Made `alloc` public. [#711](https://github.com/paritytech/parity-common/pull/711)
- Removed a reference to `sp_core` in the comments. [#710](https://github.com/paritytech/parity-common/pull/710)

## [0.1.0] - 2023-01-26
- Wrote better description for `bounded-collections`. [#709](https://github.com/paritytech/parity-common/pull/709)
- Added `bounded-collections` crate. [#708](https://github.com/paritytech/parity-common/pull/708)
12 changes: 9 additions & 3 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.1"
version = "0.1.2"
authors = ["Parity Technologies <[email protected]>"]
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 }
serde = { version = "1.0.101", default-features = false, optional = true }
codec = { version = "3.0.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,4 +19,10 @@ serde_json = "1.0.41"

[features]
default = ["std"]
std = ["serde/std", "serde/derive"]
std = [
"log/std",
"codec/std",
"scale-info/std",
"serde",
"serde/derive",
]
3 changes: 3 additions & 0 deletions bounded-collections/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Bounded Collections

Bounded types and their supporting traits.
7 changes: 4 additions & 3 deletions bounded-collections/src/bounded_btree_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,13 @@ where
mod test {
use super::*;
use crate::ConstU32;
use alloc::{vec, vec::Vec};

fn map_from_keys<K>(keys: &[K]) -> BTreeMap<K, ()>
where
K: Ord + Copy,
{
keys.iter().copied().zip(std::iter::repeat(())).collect()
keys.iter().copied().zip(core::iter::repeat(())).collect()
}

fn boundedmap_from_keys<K, S>(keys: &[K]) -> BoundedBTreeMap<K, (), S>
Expand Down Expand Up @@ -473,13 +474,13 @@ mod test {
impl Eq for Unequal {}

impl Ord for Unequal {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.0.cmp(&other.0)
}
}

impl PartialOrd for Unequal {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
Expand Down
5 changes: 3 additions & 2 deletions bounded-collections/src/bounded_btree_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ where
mod test {
use super::*;
use crate::ConstU32;
use alloc::{vec, vec::Vec};

fn set_from_keys<T>(keys: &[T]) -> BTreeSet<T>
where
Expand Down Expand Up @@ -403,13 +404,13 @@ mod test {
impl Eq for Unequal {}

impl Ord for Unequal {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.0.cmp(&other.0)
}
}

impl PartialOrd for Unequal {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
Expand Down
1 change: 1 addition & 0 deletions bounded-collections/src/bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use super::WeakBoundedVec;
use crate::{Get, TryCollect};
use alloc::{boxed::Box, vec::Vec};
use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
use core::{
marker::PhantomData,
Expand Down
2 changes: 2 additions & 0 deletions bounded-collections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
//! Collection types that have an upper limit on how many elements that they can contain, and
//! supporting traits that aid in defining the limit.

#![cfg_attr(not(feature = "std"), no_std)]

pub extern crate alloc;

pub mod bounded_btree_map;
Expand Down
2 changes: 2 additions & 0 deletions bounded-collections/src/weak_bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use super::{BoundedSlice, BoundedVec};
use crate::Get;
use alloc::vec::Vec;
use codec::{Decode, Encode, MaxEncodedLen};
use core::{
marker::PhantomData,
Expand Down Expand Up @@ -448,6 +449,7 @@ where
mod test {
use super::*;
use crate::ConstU32;
use alloc::vec;

#[test]
fn bound_returns_correct_value() {
Expand Down

0 comments on commit b9123ad

Please sign in to comment.