diff --git a/Cargo.toml b/Cargo.toml index dccfff7..feceae4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,13 @@ categories = [ "algorithms", "science" ] license = "MIT/Apache-2.0" repository = "https://github.com/rust-num/num-integer" name = "num-integer" -version = "0.1.35" +version = "0.1.36" readme = "README.md" [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 2fb6062..3320654 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![crate](https://img.shields.io/crates/v/num-integer.svg)](https://crates.io/crates/num-integer) [![documentation](https://docs.rs/num-integer/badge.svg)](https://docs.rs/num-integer) +![minimum rustc 1.8](https://img.shields.io/badge/rustc-1.8+-red.svg) [![Travis status](https://travis-ci.org/rust-num/num-integer.svg?branch=master)](https://travis-ci.org/rust-num/num-integer) `Integer` trait and functions for Rust. @@ -21,6 +22,24 @@ and this to your crate root: extern crate num_integer; ``` +## 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-integer] +version = "0.1.36" +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-integer` crate is tested for rustc 1.8 and greater. diff --git a/RELEASES.md b/RELEASES.md new file mode 100644 index 0000000..956146c --- /dev/null +++ b/RELEASES.md @@ -0,0 +1,21 @@ +# Release 0.1.36 + +- [num-integer now has its own source repository][num-356] at [rust-num/num-integer][home]. +- [Corrected the argument order documented in `Integer::is_multiple_of`][1] +- [There is now a `std` feature][5], 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, @jaystrictor + +[home]: https://github.com/rust-num/num-integer +[num-356]: https://github.com/rust-num/num/pull/356 +[1]: https://github.com/rust-num/num-integer/pull/1 +[5]: https://github.com/rust-num/num-integer/pull/5 + + +# Prior releases + +No prior release notes were kept. Thanks all the same to the many +contributors that have made this crate what it is! + diff --git a/ci/test_full.sh b/ci/test_full.sh index 37211bb..89e7273 100755 --- a/ci/test_full.sh +++ b/ci/test_full.sh @@ -8,4 +8,6 @@ echo Testing num-integer 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 a871f68..8d47294 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,12 +9,21 @@ // except according to those terms. //! Integer trait and functions. +//! +//! ## Compatibility +//! +//! The `num-integer` crate is tested for rustc 1.8 and greater. #![doc(html_root_url = "https://docs.rs/num-integer/0.1")] +#![cfg_attr(not(feature = "std"), no_std)] +#[cfg(feature = "std")] +extern crate core; + extern crate num_traits as traits; -use std::ops::Add; +use core::ops::Add; +use core::mem; use traits::{Num, Signed}; @@ -267,7 +276,7 @@ macro_rules! impl_integer_for_isize { while m != 0 { m >>= m.trailing_zeros(); - if n > m { ::std::mem::swap(&mut n, &mut m) } + if n > m { mem::swap(&mut n, &mut m) } m -= n; } @@ -312,6 +321,7 @@ macro_rules! impl_integer_for_isize { #[cfg(test)] mod $test_mod { use Integer; + use core::mem; /// Checks that the division rule holds for: /// @@ -389,7 +399,7 @@ macro_rules! impl_integer_for_isize { fn test_gcd_cmp_with_euclidean() { fn euclidean_gcd(mut m: $T, mut n: $T) -> $T { while m != 0 { - ::std::mem::swap(&mut m, &mut n); + mem::swap(&mut m, &mut n); m %= n; } @@ -526,7 +536,7 @@ macro_rules! impl_integer_for_usize { while m != 0 { m >>= m.trailing_zeros(); - if n > m { ::std::mem::swap(&mut n, &mut m) } + if n > m { mem::swap(&mut n, &mut m) } m -= n; } @@ -573,6 +583,7 @@ macro_rules! impl_integer_for_usize { #[cfg(test)] mod $test_mod { use Integer; + use core::mem; #[test] fn test_div_mod_floor() { @@ -600,7 +611,7 @@ macro_rules! impl_integer_for_usize { fn test_gcd_cmp_with_euclidean() { fn euclidean_gcd(mut m: $T, mut n: $T) -> $T { while m != 0 { - ::std::mem::swap(&mut m, &mut n); + mem::swap(&mut m, &mut n); m %= n; } n @@ -817,9 +828,10 @@ fn test_iter_binomial() { macro_rules! check_simple { ($t:ty) => { { let n: $t = 3; - let c: Vec<_> = IterBinomial::new(n).collect(); - let expected = vec![1, 3, 3, 1]; - assert_eq!(c, expected); + let expected = [1, 3, 3, 1]; + for (b, &e) in IterBinomial::new(n).zip(&expected) { + assert_eq!(b, e); + } } } } @@ -835,9 +847,8 @@ fn test_iter_binomial() { macro_rules! check_binomial { ($t:ty, $n:expr) => { { let n: $t = $n; - let c: Vec<_> = IterBinomial::new(n).collect(); let mut k: $t = 0; - for b in c { + for b in IterBinomial::new(n) { assert_eq!(b, binomial(n, k)); k += 1; }