Skip to content

Add the std feature and release 0.1.35 #2

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

Merged
merged 3 commits into from
Feb 7, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ 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]

[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 = []
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -21,6 +22,24 @@ 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.

## Releases

Release notes are available in [RELEASES.md](RELEASES.md).

## Compatibility

The `num-iter` crate is tested for rustc 1.8 and greater.
19 changes: 19 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -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!

4 changes: 3 additions & 1 deletion ci/test_full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
87 changes: 51 additions & 36 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@
// 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")]

#![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)]
Expand Down Expand Up @@ -262,9 +270,10 @@ impl<A> Iterator for RangeStepInclusive<A>

#[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]
Expand Down Expand Up @@ -317,10 +326,12 @@ mod tests {
}
}

assert!(super::range(0, 5).collect::<Vec<isize>>() == vec![0, 1, 2, 3, 4]);
assert!(super::range(-10, -1).collect::<Vec<isize>>() ==
vec![-10, -9, -8, -7, -6, -5, -4, -3, -2]);
assert!(super::range(0, 5).rev().collect::<Vec<isize>>() == 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);
Expand All @@ -334,43 +345,47 @@ mod tests {

#[test]
fn test_range_inclusive() {
assert!(super::range_inclusive(0, 5).collect::<Vec<isize>>() ==
vec![0, 1, 2, 3, 4, 5]);
assert!(super::range_inclusive(0, 5).rev().collect::<Vec<isize>>() ==
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<isize>>() == vec![200]);
assert!(super::range_inclusive(200, 200).rev().collect::<Vec<isize>>() == 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<isize>>() ==
vec![0, 5, 10, 15]);
assert!(super::range_step(20, 0, -5).collect::<Vec<isize>>() ==
vec![20, 15, 10, 5]);
assert!(super::range_step(20, 0, -6).collect::<Vec<isize>>() ==
vec![20, 14, 8, 2]);
assert!(super::range_step(200u8, 255, 50).collect::<Vec<u8>>() ==
vec![200u8, 250]);
assert!(super::range_step(200, -5, 1).collect::<Vec<isize>>() == vec![]);
assert!(super::range_step(200, 200, 1).collect::<Vec<isize>>() == 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<isize>>() ==
vec![0, 5, 10, 15, 20]);
assert!(super::range_step_inclusive(20, 0, -5).collect::<Vec<isize>>() ==
vec![20, 15, 10, 5, 0]);
assert!(super::range_step_inclusive(20, 0, -6).collect::<Vec<isize>>() ==
vec![20, 14, 8, 2]);
assert!(super::range_step_inclusive(200u8, 255, 50).collect::<Vec<u8>>() ==
vec![200u8, 250]);
assert!(super::range_step_inclusive(200, -5, 1).collect::<Vec<isize>>() ==
vec![]);
assert!(super::range_step_inclusive(200, 200, 1).collect::<Vec<isize>>() ==
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)));
}
}