Use no_std-compatible num dependencies
Rather than the `num` meta-crate, use `num-integer` and `num-traits` without default features to make them `#[no_std]`. `num-iter` is just a dev-dependency now for a few test cases. The only public change is the `impl FromPrimitive for Weekday`, but this is still the same exact trait that `num` re-exports, so this is not a breaking change.
This commit is contained in:
parent
ff962d452c
commit
8f90f405d5
|
@ -21,7 +21,8 @@ name = "chrono"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
time = "^0.1.36"
|
time = "^0.1.36"
|
||||||
num = { version = "0.1", default-features = false }
|
num-integer = { version = "0.1.36", default-features = false }
|
||||||
|
num-traits = { version = "0.2", default-features = false }
|
||||||
rustc-serialize = { version = "0.3", optional = true }
|
rustc-serialize = { version = "0.3", optional = true }
|
||||||
serde = { version = "1", optional = true }
|
serde = { version = "1", optional = true }
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ serde = { version = "1", optional = true }
|
||||||
serde_json = { version = "1" }
|
serde_json = { version = "1" }
|
||||||
serde_derive = { version = "1" }
|
serde_derive = { version = "1" }
|
||||||
bincode = { version = "0.8.0" }
|
bincode = { version = "0.8.0" }
|
||||||
|
num-iter = { version = "0.1.35", default-features = false }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
|
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
|
||||||
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
|
// December 2001](http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf)
|
||||||
|
|
||||||
pub use num::integer::{div_rem, div_floor, mod_floor, div_mod_floor};
|
pub use num_integer::{div_rem, div_floor, mod_floor, div_mod_floor};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//! A collection of parsed date and time items.
|
//! A collection of parsed date and time items.
|
||||||
//! They can be constructed incrementally while being checked for consistency.
|
//! They can be constructed incrementally while being checked for consistency.
|
||||||
|
|
||||||
use num::traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use oldtime::Duration as OldDuration;
|
use oldtime::Duration as OldDuration;
|
||||||
|
|
||||||
use {Datelike, Timelike};
|
use {Datelike, Timelike};
|
||||||
|
|
|
@ -394,7 +394,8 @@
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(const_static_lifetime))]
|
#![cfg_attr(feature = "cargo-clippy", allow(const_static_lifetime))]
|
||||||
|
|
||||||
extern crate time as oldtime;
|
extern crate time as oldtime;
|
||||||
extern crate num;
|
extern crate num_integer;
|
||||||
|
extern crate num_traits;
|
||||||
#[cfg(feature = "rustc-serialize")]
|
#[cfg(feature = "rustc-serialize")]
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
|
@ -615,7 +616,7 @@ impl Weekday {
|
||||||
/// Any weekday can be represented as an integer from 0 to 6, which equals to
|
/// Any weekday can be represented as an integer from 0 to 6, which equals to
|
||||||
/// [`Weekday::num_days_from_monday`](#method.num_days_from_monday) in this implementation.
|
/// [`Weekday::num_days_from_monday`](#method.num_days_from_monday) in this implementation.
|
||||||
/// Do not heavily depend on this though; use explicit methods whenever possible.
|
/// Do not heavily depend on this though; use explicit methods whenever possible.
|
||||||
impl num::traits::FromPrimitive for Weekday {
|
impl num_traits::FromPrimitive for Weekday {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_i64(n: i64) -> Option<Weekday> {
|
fn from_i64(n: i64) -> Option<Weekday> {
|
||||||
match n {
|
match n {
|
||||||
|
@ -930,9 +931,11 @@ pub trait Timelike: Sized {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)] extern crate num_iter;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_readme_doomsday() {
|
fn test_readme_doomsday() {
|
||||||
use num::iter::range_inclusive;
|
use num_iter::range_inclusive;
|
||||||
|
|
||||||
for y in range_inclusive(naive::MIN_DATE.year(), naive::MAX_DATE.year()) {
|
for y in range_inclusive(naive::MIN_DATE.year(), naive::MAX_DATE.year()) {
|
||||||
// even months
|
// even months
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
use std::{str, fmt};
|
use std::{str, fmt};
|
||||||
use std::ops::{Add, Sub, AddAssign, SubAssign};
|
use std::ops::{Add, Sub, AddAssign, SubAssign};
|
||||||
use num::traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use oldtime::Duration as OldDuration;
|
use oldtime::Duration as OldDuration;
|
||||||
|
|
||||||
use {Weekday, Datelike};
|
use {Weekday, Datelike};
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
use std::{str, fmt, hash};
|
use std::{str, fmt, hash};
|
||||||
use std::ops::{Add, Sub, AddAssign, SubAssign};
|
use std::ops::{Add, Sub, AddAssign, SubAssign};
|
||||||
use num::traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use oldtime::Duration as OldDuration;
|
use oldtime::Duration as OldDuration;
|
||||||
|
|
||||||
use {Weekday, Timelike, Datelike};
|
use {Weekday, Timelike, Datelike};
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#![allow(dead_code)] // some internal methods have been left for consistency
|
#![allow(dead_code)] // some internal methods have been left for consistency
|
||||||
|
|
||||||
use std::{i32, fmt};
|
use std::{i32, fmt};
|
||||||
use num::traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use Weekday;
|
use Weekday;
|
||||||
use div::{div_rem, mod_floor};
|
use div::{div_rem, mod_floor};
|
||||||
|
|
||||||
|
@ -469,12 +469,13 @@ impl fmt::Debug for Mdf {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#[cfg(test)] extern crate num_iter;
|
||||||
#[cfg(bench)] extern crate test;
|
#[cfg(bench)] extern crate test;
|
||||||
|
|
||||||
use Weekday;
|
use Weekday;
|
||||||
use super::{Of, Mdf};
|
use super::{Of, Mdf};
|
||||||
use super::{YearFlags, A, B, C, D, E, F, G, AG, BA, CB, DC, ED, FE, GF};
|
use super::{YearFlags, A, B, C, D, E, F, G, AG, BA, CB, DC, ED, FE, GF};
|
||||||
use num::iter::range_inclusive;
|
use num_iter::range_inclusive;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
|
||||||
const NONLEAP_FLAGS: [YearFlags; 7] = [A, B, C, D, E, F, G];
|
const NONLEAP_FLAGS: [YearFlags; 7] = [A, B, C, D, E, F, G];
|
||||||
|
|
Loading…
Reference in New Issue