From fdd28744940e716f2d040293078bdffa9db18af8 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 6 Feb 2018 21:00:45 -0800 Subject: [PATCH 1/3] Add a min-rustc badge and document compatibility --- README.md | 1 + src/lib.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/README.md b/README.md index a409e1d..5b71fe8 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![crate](https://img.shields.io/crates/v/num-iter.svg)](https://crates.io/crates/num-iter) [![documentation](https://docs.rs/num-iter/badge.svg)](https://docs.rs/num-iter) +![minimum rustc 1.8](https://img.shields.io/badge/rustc-1.8+-red.svg) [![Travis status](https://travis-ci.org/rust-num/num-iter.svg?branch=master)](https://travis-ci.org/rust-num/num-iter) Generic `Range` iterators for Rust. diff --git a/src/lib.rs b/src/lib.rs index b9ed819..6d487c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,10 @@ // except according to those terms. //! External iterators for generic mathematics +//! +//! ## Compatibility +//! +//! The `num-iter` crate is tested for rustc 1.8 and greater. #![doc(html_root_url = "https://docs.rs/num-iter/0.1")] From a67ea7af8d42232b8a79c4fc178ca218c1d95452 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 6 Feb 2018 21:21:47 -0800 Subject: [PATCH 2/3] Introduce the std feature So far, it only toggles whether to build with `#![no_std]`. --- Cargo.toml | 10 ++++-- README.md | 14 +++++++++ ci/test_full.sh | 4 ++- src/lib.rs | 83 ++++++++++++++++++++++++++++--------------------- 4 files changed, 72 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6ce3813..234860c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,13 @@ readme = "README.md" [dependencies] [dependencies.num-integer] -version = "0.1.32" +version = "0.1.36" +default-features = false [dependencies.num-traits] -version = "0.1.32" +version = "0.2.0" +default-features = false + +[features] +default = ["std"] +std = [] diff --git a/README.md b/README.md index 5b71fe8..be3d102 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,20 @@ and this to your crate root: extern crate num_iter; ``` +## Features + +This crate can be used without the standard library (`#![no_std]`) by disabling +the default `std` feature. Use this in `Cargo.toml`: + +```toml +[dependencies.num-iter] +version = "0.1.35" +default-features = false +``` + +There is no functional difference with and without `std` at this time, but +there may be in the future. + ## Compatibility The `num-iter` crate is tested for rustc 1.8 and greater. diff --git a/ci/test_full.sh b/ci/test_full.sh index 32ab0bd..9bdc34d 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -8,4 +8,6 @@ echo Testing num-iter on rustc ${TRAVIS_RUST_VERSION} cargo build --verbose cargo test --verbose -# We have no features to test... +# test `no_std` +cargo build --verbose --no-default-features +cargo test --verbose --no-default-features diff --git a/src/lib.rs b/src/lib.rs index 6d487c1..49ae753 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,12 +16,16 @@ #![doc(html_root_url = "https://docs.rs/num-iter/0.1")] +#![cfg_attr(not(feature = "std"), no_std)] +#[cfg(feature = "std")] +extern crate core; + extern crate num_traits as traits; extern crate num_integer as integer; use integer::Integer; use traits::{Zero, One, CheckedAdd, ToPrimitive}; -use std::ops::{Add, Sub}; +use core::ops::{Add, Sub}; /// An iterator over the range [start, stop) #[derive(Clone)] @@ -266,9 +270,10 @@ impl Iterator for RangeStepInclusive #[cfg(test)] mod tests { - use std::usize; - use std::ops::{Add, Mul}; - use std::cmp::Ordering; + use core::usize; + use core::ops::{Add, Mul}; + use core::cmp::Ordering; + use core::iter; use traits::{One, ToPrimitive}; #[test] @@ -321,10 +326,12 @@ mod tests { } } - assert!(super::range(0, 5).collect::>() == vec![0, 1, 2, 3, 4]); - assert!(super::range(-10, -1).collect::>() == - vec![-10, -9, -8, -7, -6, -5, -4, -3, -2]); - assert!(super::range(0, 5).rev().collect::>() == vec![4, 3, 2, 1, 0]); + assert!(super::range(0, 5) + .eq([0, 1, 2, 3, 4].iter().cloned())); + assert!(super::range(-10, -1) + .eq([-10, -9, -8, -7, -6, -5, -4, -3, -2].iter().cloned())); + assert!(super::range(0, 5).rev() + .eq([4, 3, 2, 1, 0].iter().cloned())); assert_eq!(super::range(200, -5).count(), 0); assert_eq!(super::range(200, -5).rev().count(), 0); assert_eq!(super::range(200, 200).count(), 0); @@ -338,43 +345,47 @@ mod tests { #[test] fn test_range_inclusive() { - assert!(super::range_inclusive(0, 5).collect::>() == - vec![0, 1, 2, 3, 4, 5]); - assert!(super::range_inclusive(0, 5).rev().collect::>() == - vec![5, 4, 3, 2, 1, 0]); + assert!(super::range_inclusive(0, 5) + .eq([0, 1, 2, 3, 4, 5].iter().cloned())); + assert!(super::range_inclusive(0, 5).rev() + .eq([5, 4, 3, 2, 1, 0].iter().cloned())); assert_eq!(super::range_inclusive(200, -5).count(), 0); assert_eq!(super::range_inclusive(200, -5).rev().count(), 0); - assert!(super::range_inclusive(200, 200).collect::>() == vec![200]); - assert!(super::range_inclusive(200, 200).rev().collect::>() == vec![200]); + assert!(super::range_inclusive(200, 200) + .eq(iter::once(200))); + assert!(super::range_inclusive(200, 200).rev() + .eq(iter::once(200))); } #[test] fn test_range_step() { - assert!(super::range_step(0, 20, 5).collect::>() == - vec![0, 5, 10, 15]); - assert!(super::range_step(20, 0, -5).collect::>() == - vec![20, 15, 10, 5]); - assert!(super::range_step(20, 0, -6).collect::>() == - vec![20, 14, 8, 2]); - assert!(super::range_step(200u8, 255, 50).collect::>() == - vec![200u8, 250]); - assert!(super::range_step(200, -5, 1).collect::>() == vec![]); - assert!(super::range_step(200, 200, 1).collect::>() == vec![]); + assert!(super::range_step(0, 20, 5) + .eq([0, 5, 10, 15].iter().cloned())); + assert!(super::range_step(20, 0, -5) + .eq([20, 15, 10, 5].iter().cloned())); + assert!(super::range_step(20, 0, -6) + .eq([20, 14, 8, 2].iter().cloned())); + assert!(super::range_step(200u8, 255, 50) + .eq([200u8, 250].iter().cloned())); + assert!(super::range_step(200, -5, 1) + .eq(iter::empty())); + assert!(super::range_step(200, 200, 1) + .eq(iter::empty())); } #[test] fn test_range_step_inclusive() { - assert!(super::range_step_inclusive(0, 20, 5).collect::>() == - vec![0, 5, 10, 15, 20]); - assert!(super::range_step_inclusive(20, 0, -5).collect::>() == - vec![20, 15, 10, 5, 0]); - assert!(super::range_step_inclusive(20, 0, -6).collect::>() == - vec![20, 14, 8, 2]); - assert!(super::range_step_inclusive(200u8, 255, 50).collect::>() == - vec![200u8, 250]); - assert!(super::range_step_inclusive(200, -5, 1).collect::>() == - vec![]); - assert!(super::range_step_inclusive(200, 200, 1).collect::>() == - vec![200]); + assert!(super::range_step_inclusive(0, 20, 5) + .eq([0, 5, 10, 15, 20].iter().cloned())); + assert!(super::range_step_inclusive(20, 0, -5) + .eq([20, 15, 10, 5, 0].iter().cloned())); + assert!(super::range_step_inclusive(20, 0, -6) + .eq([20, 14, 8, 2].iter().cloned())); + assert!(super::range_step_inclusive(200u8, 255, 50) + .eq([200u8, 250].iter().cloned())); + assert!(super::range_step_inclusive(200, -5, 1) + .eq(iter::empty())); + assert!(super::range_step_inclusive(200, 200, 1) + .eq(iter::once(200))); } } From 9e8ae7f205750fa29bf783523152bcbb15230be5 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 6 Feb 2018 21:27:55 -0800 Subject: [PATCH 3/3] Release 0.1.35 --- Cargo.toml | 2 +- README.md | 4 ++++ RELEASES.md | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 RELEASES.md diff --git a/Cargo.toml b/Cargo.toml index 234860c..d4f64cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ categories = [ "algorithms", "science" ] license = "MIT/Apache-2.0" repository = "https://github.com/rust-num/num-iter" name = "num-iter" -version = "0.1.34" +version = "0.1.35" readme = "README.md" [dependencies] diff --git a/README.md b/README.md index be3d102..c138f03 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,10 @@ default-features = false There is no functional difference with and without `std` at this time, but there may be in the future. +## Releases + +Release notes are available in [RELEASES.md](RELEASES.md). + ## Compatibility The `num-iter` crate is tested for rustc 1.8 and greater. diff --git a/RELEASES.md b/RELEASES.md new file mode 100644 index 0000000..08868bd --- /dev/null +++ b/RELEASES.md @@ -0,0 +1,19 @@ +# Release 0.1.35 + +- [num-iter now has its own source repository][num-356] at [rust-num/num-iter][home]. +- [There is now a `std` feature][2], enabled by default, along with the implication + that building *without* this feature makes this a `#[no_std]` crate. + - There is no difference in the API at this time. + +**Contributors**: @cuviper + +[home]: https://github.com/rust-num/num-iter +[num-356]: https://github.com/rust-num/num/pull/356 +[2]: https://github.com/rust-num/num-iter/pull/2 + + +# Prior releases + +No prior release notes were kept. Thanks all the same to the many +contributors that have made this crate what it is! +