From 8d46907f134d82258b7005c7bff55cac41109c92 Mon Sep 17 00:00:00 2001 From: Kamal Ahmad Date: Sat, 9 Nov 2024 12:44:02 +0500 Subject: [PATCH 1/3] Add no_std support for bounded-vec Remove cdylib target as that requires pulling in a global allocator to build for doctests --- Cargo.toml | 14 +++++++------- src/bounded_vec.rs | 10 ++++++---- src/lib.rs | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 01ecbb1..154d60a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,16 +7,16 @@ edition = "2018" description = "Non-empty rust Vec wrapper with type guarantees on lower and upper bounds for items quantity." repository = "https://github.com/ergoplatform/bounded-vec" -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] -thiserror = "1" -serde = {version = "1.0.123", features = ["derive"], optional = true} -proptest = {version = "1.0.0", optional = true} +serde = { version = "1.0.123", default-features = false, features = [ + "alloc", + "derive", +], optional = true } +thiserror = { version = "2", default-features = false } +proptest = { version = "1.0.0", optional = true } [features] arbitrary = ["proptest"] [dev-dependencies] -proptest = {version = "1.0.0"} +proptest = { version = "1.0.0" } diff --git a/src/bounded_vec.rs b/src/bounded_vec.rs index 35a9573..4019208 100644 --- a/src/bounded_vec.rs +++ b/src/bounded_vec.rs @@ -1,8 +1,9 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::convert::{TryFrom, TryInto}; +use core::slice::{Iter, IterMut}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; -use std::slice::{Iter, IterMut}; -use std::vec; use thiserror::Error; /// Non-empty Vec bounded with minimal (L - lower bound) and maximal (U - upper bound) items quantity @@ -463,7 +464,7 @@ mod arbitrary { #[allow(clippy::unwrap_used)] #[cfg(test)] mod tests { - use std::convert::TryInto; + use core::convert::TryInto; use super::*; @@ -597,6 +598,7 @@ mod tests { mod arb_tests { use super::*; + use alloc::format; use proptest::prelude::*; proptest! { diff --git a/src/lib.rs b/src/lib.rs index 8bb63d7..ce49144 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ //! Non-empty Vec wrapper with lower and upper bounds on items quantity +#![no_std] // Coding conventions #![forbid(unsafe_code)] #![deny(non_upper_case_globals)] @@ -13,6 +14,8 @@ #![deny(clippy::unwrap_used)] #![deny(clippy::expect_used)] +extern crate alloc; + mod bounded_vec; pub use crate::bounded_vec::*; From b26488e1a494e6f45a4e7f3767d1569736d04648 Mon Sep 17 00:00:00 2001 From: Kamal Ahmad Date: Tue, 26 Nov 2024 10:07:15 +0500 Subject: [PATCH 2/3] Clippy --- src/bounded_vec.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bounded_vec.rs b/src/bounded_vec.rs index 4019208..4d579e9 100644 --- a/src/bounded_vec.rs +++ b/src/bounded_vec.rs @@ -387,7 +387,7 @@ impl<'a, T, const L: usize, const U: usize> IntoIterator for &'a BoundedVec; fn into_iter(self) -> Self::IntoIter { - (&self.inner).iter() + self.inner.iter() } } @@ -396,7 +396,7 @@ impl<'a, T, const L: usize, const U: usize> IntoIterator for &'a mut BoundedVec< type IntoIter = core::slice::IterMut<'a, T>; fn into_iter(self) -> Self::IntoIter { - (&mut self.inner).iter_mut() + self.inner.iter_mut() } } From 0eb104e114c1387f33e88bc48b33951900767249 Mon Sep 17 00:00:00 2001 From: Kamal Ahmad Date: Tue, 26 Nov 2024 10:22:02 +0500 Subject: [PATCH 3/3] ci: fix tarpaulin code coverage --- .github/workflows/ci.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4b19aa..c32340f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,13 +74,20 @@ jobs: with: command: test args: --verbose --release - - name: rust-tarpaulin code coverage check - if: matrix.os == 'ubuntu-latest' - uses: actions-rs/tarpaulin@master - with: - args: '--timeout=360 -v --out Lcov' + + test_coverage: + name: Code coverage in tests + runs-on: ubuntu-latest + container: + image: xd009642/tarpaulin:latest + options: --security-opt seccomp=unconfined + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Generate code coverage + run: | + cargo tarpaulin --avoid-cfg-tarpaulin --timeout=360 --out lcov - name: Push code coverage results to coveralls.io - if: matrix.os == 'ubuntu-latest' uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -115,7 +122,7 @@ jobs: with: command: test args: --verbose --release --all-features - + doc-links: name: Intra-documentation links runs-on: ubuntu-latest