diff --git a/.travis.yml b/.travis.yml index c33f974d..fb2d96e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ matrix: cargo test --verbose --no-default-features --features "f32 si" cargo test --verbose --no-default-features --features "autoconvert f32 si use_serde" cargo test --verbose --no-run --no-default-features --features "autoconvert usize isize bigint bigrational si std use_serde" - cargo test --verbose --no-run --no-default-features --features "autoconvert usize u8 u16 u32 u64 isize i8 i16 i32 i64 bigint biguint rational rational32 rational64 bigrational f32 f64 std use_serde" + cargo test --verbose --no-run --no-default-features --features "autoconvert usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 bigint biguint rational rational32 rational64 bigrational f32 f64 std use_serde" - name: Rustfmt rust: 1.35.0 install: diff --git a/Cargo.toml b/Cargo.toml index 95d90098..d4dc7218 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,11 +54,13 @@ u8 = ["rational-support"] u16 = ["rational-support"] u32 = ["rational-support"] u64 = ["rational-support"] +u128 = ["rational-support"] isize = ["rational-support"] i8 = ["rational-support"] i16 = ["rational-support"] i32 = ["rational-support"] i64 = ["rational-support"] +i128 = ["rational-support"] bigint = ["bigint-support"] biguint = ["bigint-support"] rational = ["rational-support"] diff --git a/README.md b/README.md index ce900c2e..b054d57e 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,8 @@ uom = { default-features = false, features = [ "autoconvert", # automatic base unit conversion. - "usize", "u8", "u16", "u32", "u64", # Unsigned integer storage types. - "isize", "i8", "i16", "i32", "i64", # Signed integer storage types. + "usize", "u8", "u16", "u32", "u64", "u128", # Unsigned integer storage types. + "isize", "i8", "i16", "i32", "i64", "i128", # Signed integer storage types. "bigint", "biguint", # Arbitrary width integer storage types. "rational", "rational32", "rational64", "bigrational", # Integer ratio storage types. "f32", "f64", # Floating point storage types. @@ -96,10 +96,10 @@ uom = { Disabling the feature only allows for quantities with the same base units to directly interact. The feature exists to account for compiler limitations where zero-cost code is not generated for non-floating point underlying storage types. - * `usize`, `u8`, `u16`, `u32`, `u64`, `isize`, `i8`, `i16`, `i32`, `i64`, `bigint`, `biguint`, - `rational`, `rational32`, `rational64`, `bigrational`, `f32`, `f64` -- Features to enable - underlying storage types. At least one of these features must be enabled. `f32` and `f64` are - enabled by default. See the [Design](#design) section for implications of choosing different + * `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`, `i128`, `bigint`, + `biguint`, `rational`, `rational32`, `rational64`, `bigrational`, `f32`, `f64` -- Features to + enable underlying storage types. At least one of these features must be enabled. `f32` and `f64` + are enabled by default. See the [Design](#design) section for implications of choosing different underlying storage types. * `si` -- Feature to include the pre-built [International System of Units][si] (SI). Enabled by default. @@ -121,9 +121,9 @@ storage type (e.g. `f32`). `uom` normalizes values to the [base unit](http://jcgm.bipm.org/vim/en/1.10.html) for the quantity. Alternative base units can be used by executing the macro defined for the system of quantities -(`ISQ!` for the SI). `uom` supports `usize`, `u8`, `u16`, `u32`, `u64`, `isize`, `i8`, `i16`, `i32`, -`i64`, `bigint`, `biguint`, `rational`, `rational32`, `rational64`, `bigrational`, `f32`, and `f64` -as the underlying storage type. +(`ISQ!` for the SI). `uom` supports `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, +`i16`, `i32`, `i64`, `i128`, `bigint`, `biguint`, `rational`, `rational32`, `rational64`, +`bigrational`, `f32`, and `f64` as the underlying storage type. A consequence of normalizing values to the base unit is that some values may not be able to be represented or can't be precisely represented for floating point and rational underlying storage diff --git a/src/lib.rs b/src/lib.rs index b5d8c812..838f8019 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,8 +70,8 @@ //! default-features = false, //! features = [ //! "autoconvert", # automatic base unit conversion. -//! "usize", "u8", "u16", "u32", "u64", # Unsigned integer storage types. -//! "isize", "i8", "i16", "i32", "i64", # Signed integer storage types. +//! "usize", "u8", "u16", "u32", "u64", "u128", # Unsigned integer storage types. +//! "isize", "i8", "i16", "i32", "i64", "i128", # Signed integer storage types. //! "bigint", "biguint", # Arbitrary width integer storage types. //! "rational", "rational32", "rational64", "bigrational", # Integer ratio storage types. //! "f32", "f64", # Floating point storage types. @@ -85,10 +85,11 @@ //! operators. Disabling the feature only allows for quantities with the same base units to //! directly interact. The feature exists to account for compiler limitations where zero-cost //! code is not generated for non-floating point underlying storage types. -//! * `usize`, `u8`, `u16`, `u32`, `u64`, `isize`, `i8`, `i16`, `i32`, `i64`, `bigint`, `biguint`, -//! `rational`, `rational32`, `rational64`, `bigrational`, `f32`, `f64` -- Features to enable -//! underlying storage types. At least one of these features must be enabled. `f32` and `f64` are -//! enabled by default. See the [Design](#design) section for implications of choosing different +//! * `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`, `i128`, +//! `bigint`, `biguint`, `rational`, `rational32`, `rational64`, `bigrational`, `f32`, `f64` -- +//! Features to enable underlying storage types. At least one of these features must be enabled. +//! `f32` and `f64` are enabled by default. See the [Design](#design) section for implications +//! of choosing different //! underlying storage types. //! * `si` -- Feature to include the pre-built [International System of Units][si] (SI). Enabled by //! default. @@ -110,9 +111,9 @@ //! //! `uom` normalizes values to the [base unit](http://jcgm.bipm.org/vim/en/1.10.html) for the //! quantity. Alternative base units can be used by executing the macro defined for the system of -//! quantities (`ISQ!` for the SI). `uom` supports `usize`, `u8`, `u16`, `u32`, `u64`, `isize`, -//! `i8`, `i16`, `i32`, `i64`, `bigint`, `biguint`, `rational`, `rational32`, `rational64`, -//! `bigrational`, `f32`, and `f64` as the underlying storage type. +//! quantities (`ISQ!` for the SI). `uom` supports `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, +//! `isize`, `i8`, `i16`, `i32`, `i64`, `i128`, `bigint`, `biguint`, `rational`, `rational32`, +//! `rational64`, `bigrational`, `f32`, and `f64` as the underlying storage type. //! //! A consequence of normalizing values to the base unit is that some values may not be able to be //! represented or can't be precisely represented for floating point and rational underlying @@ -179,7 +180,9 @@ #[cfg_attr(rustfmt, rustfmt_skip)] #[cfg(not(any( feature = "usize", feature = "u8", feature = "u16", feature = "u32", feature = "u64", + feature = "u128", feature = "isize", feature = "i8", feature = "i16", feature = "i32", feature = "i64", + feature = "i128", feature = "bigint", feature = "biguint", feature = "rational", feature = "rational32", feature = "rational64", feature = "bigrational", feature = "f32", feature = "f64", )))] diff --git a/src/storage_types.rs b/src/storage_types.rs index 997ca151..072b86dd 100644 --- a/src/storage_types.rs +++ b/src/storage_types.rs @@ -1,19 +1,21 @@ -/// Macro to duplicate code a per-storage type basis. The given code is duplicated in new modules -/// named for each storage type. A type alias, `V`, is generated that code can use for the type. -/// `@...` match arms are considered private. +/// Macro to duplicate code on a per-storage type basis. The given code is duplicated in new +/// modules named for each storage type. A type alias, `V`, is generated that code can use for the +/// type. `@...` match arms are considered private. /// /// * `$attr`: Module attributes. Generally used to set documentation comments for storage type /// modules generated by the macro. /// * `$T`: Types to generate a module for. Accepts all underlying storage types along with a number /// of different categories: -/// * `All`: `usize`, `u8`, `u16`, `u32`, `u64`, `isize`, `i8`, `i16`, `i32`, `i64`, `BigInt`, -/// `BigUint`, `Rational`, `Rational32`, `Rational64`, `BigRational`, `f32`, and `f64`. -/// * `PrimInt`: `usize`, `u8`, `u16`, `u32`, `u64`, `isize`, `i8`, `i16`, `i32`, `i64`. +/// * `All`: `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`, +/// `i128`, `BigInt`, `BigUint`, `Rational`, `Rational32`, `Rational64`, `BigRational`, `f32`, +/// and `f64`. +/// * `PrimInt`: `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`, +/// and `i128`. /// * `Ratio`: `Rational`, `Rational32`, `Rational64`, and `BigRational`. /// * `Float`: `f32` and `f64`. -/// * `Signed`: `isize`, `i8`, `i16`, `i32`, `i64`, `BigInt`, `Rational`, `Rational32`, +/// * `Signed`: `isize`, `i8`, `i16`, `i32`, `i64`, `i128`, `BigInt`, `Rational`, `Rational32`, /// `Rational64`, `BigRational`, `f32`, and `f64`. -/// * `Unsigned`: `usize`, `u8`, `u16`, `u32`, `u64`, and `BigUint`. +/// * `Unsigned`: `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, and `BigUint`. /// * `$tt`: Code to place into each storage type module. /// #[cfg_attr(all(feature = "f32", feature = "f64"), doc = " ```rust")] @@ -59,6 +61,9 @@ macro_rules! storage_types { (@type ($(#[$attr:meta])*) @$M:ident u64 ($($tt:tt)*)) => { storage_type_u64!(($(#[$attr])*) @$M ($($tt)*)); }; + (@type ($(#[$attr:meta])*) @$M:ident u128 ($($tt:tt)*)) => { + storage_type_u128!(($(#[$attr])*) @$M ($($tt)*)); + }; (@type ($(#[$attr:meta])*) @$M:ident isize ($($tt:tt)*)) => { storage_type_isize!(($(#[$attr])*) @$M ($($tt)*)); }; @@ -74,6 +79,9 @@ macro_rules! storage_types { (@type ($(#[$attr:meta])*) @$M:ident i64 ($($tt:tt)*)) => { storage_type_i64!(($(#[$attr])*) @$M ($($tt)*)); }; + (@type ($(#[$attr:meta])*) @$M:ident i128 ($($tt:tt)*)) => { + storage_type_i128!(($(#[$attr])*) @$M ($($tt)*)); + }; (@type ($(#[$attr:meta])*) @$M:ident BigInt ($($tt:tt)*)) => { storage_type_bigint!(($(#[$attr])*) @$M ($($tt)*)); }; @@ -104,11 +112,13 @@ macro_rules! storage_types { storage_types!(@type ($(#[$attr])*) @$M u16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u64 ($($tt)*)); + storage_types!(@type ($(#[$attr])*) @$M u128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M isize ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i8 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i64 ($($tt)*)); + storage_types!(@type ($(#[$attr])*) @$M i128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M BigInt ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M BigUint ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M Rational ($($tt)*)); @@ -124,11 +134,13 @@ macro_rules! storage_types { storage_types!(@type ($(#[$attr])*) @$M u16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u64 ($($tt)*)); + storage_types!(@type ($(#[$attr])*) @$M u128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M isize ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i8 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i64 ($($tt)*)); + storage_types!(@type ($(#[$attr])*) @$M i128 ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Ratio ($($tt:tt)*)) => { storage_types!(@type ($(#[$attr])*) @$M Rational ($($tt)*)); @@ -146,6 +158,7 @@ macro_rules! storage_types { storage_types!(@type ($(#[$attr])*) @$M i16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i64 ($($tt)*)); + storage_types!(@type ($(#[$attr])*) @$M i128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M BigInt ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M Rational ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M Rational32 ($($tt)*)); @@ -160,6 +173,7 @@ macro_rules! storage_types { storage_types!(@type ($(#[$attr])*) @$M u16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u64 ($($tt)*)); + storage_types!(@type ($(#[$attr])*) @$M u128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M BigUint ($($tt)*)); }; (@mod ($(#[$attr:meta])*) $M:ident, $V:ty; ($($tt:tt)*)) => { @@ -218,11 +232,13 @@ storage_type_types! { storage_type_u16!("u16", u16, u16); storage_type_u32!("u32", u32, u32); storage_type_u64!("u64", u64, u64); + storage_type_u128!("u128", u128, u128); storage_type_isize!("isize", isize, isize); storage_type_i8!("i8", i8, i8); storage_type_i16!("i16", i16, i16); storage_type_i32!("i32", i32, i32); storage_type_i64!("i64", i64, i64); + storage_type_i128!("i128", i128, i128); storage_type_bigint!("bigint", bigint, $crate::num::BigInt); storage_type_biguint!("biguint", biguint, $crate::num::BigUint); storage_type_rational!("rational", rational, $crate::num::Rational); diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 12b2b393..0483d564 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -140,7 +140,8 @@ impl ::lib::ops::Deref for A { mod a_struct { storage_types! { - types: Float, PrimInt; + // Quickcheck 0.8 required for i128/u128 support. Use PrimInt after upgrade. + types: Float, usize, u8, u16, u32, u64, isize, i8, i16, i32, i64; use super::super::A; @@ -155,7 +156,7 @@ mod a_struct { } storage_types! { - types: BigInt, BigUint, Ratio; + types: BigInt, BigUint, Ratio, i128, u128; use num::FromPrimitive; use super::super::A;