diff --git a/Cargo.toml b/Cargo.toml index 2a0810fbf..904447299 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ license = "MIT/Apache-2.0" description = "Typenum is a Rust library for type-level numbers evaluated at compile time. It currently supports bits, unsigned integers, and signed integers. It also provides a type-level array of type-level numbers, but its implementation is incomplete." categories = ["no-std"] + edition = "2018" [lib] name = "typenum" diff --git a/build/main.rs b/build/main.rs index 6e4fa0552..a886ac3da 100644 --- a/build/main.rs +++ b/build/main.rs @@ -151,11 +151,11 @@ We also define the aliases `False` and `True` for `B0` and `B1`, respectively. */ #[allow(missing_docs)] pub mod consts {{ - use uint::{{UInt, UTerm}}; - use int::{{PInt, NInt}}; + use crate::uint::{{UInt, UTerm}}; + use crate::int::{{PInt, NInt}}; - pub use bit::{{B0, B1}}; - pub use int::Z0; + pub use crate::bit::{{B0, B1}}; + pub use crate::int::Z0; pub type True = B1; pub type False = B0; diff --git a/src/bit.rs b/src/bit.rs index 8b2550c4f..208af8c07 100644 --- a/src/bit.rs +++ b/src/bit.rs @@ -9,11 +9,10 @@ //! - From `core::ops`: `BitAnd`, `BitOr`, `BitXor`, and `Not`. //! - From `typenum`: `Same` and `Cmp`. +use crate::{private::InternalMarker, Cmp, Equal, Greater, Less, NonZero, PowerOfTwo}; use core::ops::{BitAnd, BitOr, BitXor, Not}; -use private::InternalMarker; -use {Cmp, Equal, Greater, Less, NonZero, PowerOfTwo}; -pub use marker_traits::Bit; +pub use crate::marker_traits::Bit; /// The type-level bit 0. #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)] @@ -255,7 +254,7 @@ impl Cmp for B1 { } } -use Min; +use crate::Min; impl Min for B0 { type Output = B0; #[inline] @@ -285,7 +284,7 @@ impl Min for B1 { } } -use Max; +use crate::Max; impl Max for B0 { type Output = B0; #[inline] diff --git a/src/int.rs b/src/int.rs index 2d3ed34da..6d0f0d84f 100644 --- a/src/int.rs +++ b/src/int.rs @@ -25,19 +25,17 @@ //! assert_eq!(>::Output::to_i32(), -1); //! assert_eq!(>::Output::to_i32(), -1); //! ``` -//! +pub use crate::marker_traits::Integer; +use crate::{ + bit::{Bit, B0, B1}, + consts::{N1, P1, U0, U1}, + private::{Internal, InternalMarker, PrivateDivInt, PrivateIntegerAdd, PrivateRem}, + uint::{UInt, Unsigned}, + Cmp, Equal, Greater, Less, NonZero, Pow, PowerOfTwo, +}; use core::ops::{Add, Div, Mul, Neg, Rem, Sub}; -use bit::{Bit, B0, B1}; -use consts::{N1, P1, U0, U1}; -use private::{Internal, InternalMarker}; -use private::{PrivateDivInt, PrivateIntegerAdd, PrivateRem}; -use uint::{UInt, Unsigned}; -use {Cmp, Equal, Greater, Less, NonZero, Pow, PowerOfTwo}; - -pub use marker_traits::Integer; - /// Type-level signed integers with positive sign. #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)] pub struct PInt { @@ -610,7 +608,7 @@ impl_int_div!(NInt, NInt, PInt); // --------------------------------------------------------------------------------------- // PartialDiv -use {PartialDiv, Quot}; +use crate::{PartialDiv, Quot}; impl PartialDiv for M where @@ -888,7 +886,7 @@ where // --------------------------------------------------------------------------------------- // Gcd -use {Gcd, Gcf}; +use crate::{Gcd, Gcf}; impl Gcd for Z0 { type Output = Z0; @@ -960,7 +958,7 @@ where // --------------------------------------------------------------------------------------- // Min -use {Max, Maximum, Min, Minimum}; +use crate::{Max, Maximum, Min, Minimum}; impl Min for Z0 { type Output = Z0; @@ -1179,8 +1177,7 @@ where #[cfg(test)] mod tests { - use consts::*; - use Integer; + use crate::{consts::*, Integer}; #[test] fn to_ix_min() { diff --git a/src/lib.rs b/src/lib.rs index a78d487ff..bf616a20e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,15 +88,16 @@ pub mod uint; pub mod array; -pub use consts::*; -pub use generated::consts; -pub use marker_traits::*; -pub use operator_aliases::*; -pub use type_operators::*; - -pub use array::{ATerm, TArr}; -pub use int::{NInt, PInt}; -pub use uint::{UInt, UTerm}; +pub use crate::{ + array::{ATerm, TArr}, + consts::*, + generated::consts, + int::{NInt, PInt}, + marker_traits::*, + operator_aliases::*, + type_operators::*, + uint::{UInt, UTerm}, +}; /// A potential output from `Cmp`, this is the type equivalent to the enum variant /// `core::cmp::Ordering::Greater`. @@ -141,7 +142,8 @@ impl Ord for Equal { #[macro_export] macro_rules! assert_type_eq { ($a:ty, $b:ty) => { - const _: core::marker::PhantomData<<$a as $crate::Same<$b>>::Output> = core::marker::PhantomData; + const _: core::marker::PhantomData<<$a as $crate::Same<$b>>::Output> = + core::marker::PhantomData; }; } @@ -149,6 +151,7 @@ macro_rules! assert_type_eq { #[macro_export] macro_rules! assert_type { ($a:ty) => { - const _: core::marker::PhantomData<<$a as $crate::Same>::Output> = core::marker::PhantomData; + const _: core::marker::PhantomData<<$a as $crate::Same>::Output> = + core::marker::PhantomData; }; } diff --git a/src/operator_aliases.rs b/src/operator_aliases.rs index 490ad38d0..fa3174cf7 100644 --- a/src/operator_aliases.rs +++ b/src/operator_aliases.rs @@ -7,7 +7,6 @@ //! //! ```rust //! # #[macro_use] extern crate typenum; -//! # fn main() { //! use std::ops::Mul; //! use typenum::{Prod, P5, P7}; //! @@ -15,14 +14,15 @@ //! type Y = Prod; //! //! assert_type_eq!(X, Y); -//! # } //! ``` //! //! // Aliases!!! +use crate::type_operators::{ + Abs, Cmp, Gcd, Len, Logarithm2, Max, Min, PartialDiv, Pow, SquareRoot, +}; use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Rem, Shl, Shr, Sub}; -use type_operators::{Abs, Cmp, Gcd, Len, Logarithm2, Max, Min, PartialDiv, Pow, SquareRoot}; /// Alias for the associated type of `BitAnd`: `And = >::Output` pub type And = >::Output; @@ -64,12 +64,12 @@ pub type Exp = >::Output; pub type Gcf = >::Output; /// Alias to make it easy to add 1: `Add1 = >::Output` -pub type Add1 = >::Output; +pub type Add1 = >::Output; /// Alias to make it easy to subtract 1: `Sub1 = >::Output` -pub type Sub1 = >::Output; +pub type Sub1 = >::Output; /// Alias to make it easy to multiply by 2. `Double = Shleft` -pub type Double = Shleft; +pub type Double = Shleft; /// Alias to make it easy to square. `Square = >::Output` pub type Square = ::Output; @@ -91,7 +91,9 @@ pub type Minimum = >::Output; /// Alias for the associated type of `Max`: `Maximum = >::Output` pub type Maximum = >::Output; -use type_operators::{IsEqual, IsGreater, IsGreaterOrEqual, IsLess, IsLessOrEqual, IsNotEqual}; +use crate::type_operators::{ + IsEqual, IsGreater, IsGreaterOrEqual, IsLess, IsLessOrEqual, IsNotEqual, +}; /// Alias for the associated type of `IsLess`: `Le = >::Output` pub type Le = >::Output; /// Alias for the associated type of `IsEqual`: `Eq = >::Output` diff --git a/src/private.rs b/src/private.rs index c040ba55b..97b2ad80f 100644 --- a/src/private.rs +++ b/src/private.rs @@ -17,12 +17,13 @@ //! //! Note: Aliases for private type operators will all be named simply that operator followed //! by an abbreviated name of its associated type. -//! #![doc(hidden)] -use bit::{Bit, B0, B1}; -use uint::{UInt, UTerm, Unsigned}; +use crate::{ + bit::{Bit, B0, B1}, + uint::{UInt, UTerm, Unsigned}, +}; /// A marker for restricting a method on a public trait to internal use only. pub(crate) enum Internal {} @@ -63,7 +64,7 @@ pub type InvertOut = ::Output; pub trait PrivateInvert { type Output; - fn private_invert(self, Rhs) -> Self::Output; + fn private_invert(self, rhs: Rhs) -> Self::Output; } pub type PrivateInvertOut = >::Output; @@ -80,7 +81,7 @@ pub struct InvertedUInt { pub trait PrivateAnd { type Output; - fn private_and(self, Rhs) -> Self::Output; + fn private_and(self, rhs: Rhs) -> Self::Output; } pub type PrivateAndOut = >::Output; @@ -88,7 +89,7 @@ pub type PrivateAndOut = >::Output; pub trait PrivateXor { type Output; - fn private_xor(self, Rhs) -> Self::Output; + fn private_xor(self, rhs: Rhs) -> Self::Output; } pub type PrivateXorOut = >::Output; @@ -96,7 +97,7 @@ pub type PrivateXorOut = >::Output; pub trait PrivateSub { type Output; - fn private_sub(self, Rhs) -> Self::Output; + fn private_sub(self, rhs: Rhs) -> Self::Output; } pub type PrivateSubOut = >::Output; @@ -106,14 +107,14 @@ pub type PrivateSubOut = >::Output; pub trait PrivateIntegerAdd { type Output; - fn private_integer_add(self, C, N) -> Self::Output; + fn private_integer_add(self, _: C, _: N) -> Self::Output; } pub type PrivateIntegerAddOut =

>::Output; pub trait PrivatePow { type Output; - fn private_pow(self, Y, N) -> Self::Output; + fn private_pow(self, _: Y, _: N) -> Self::Output; } pub type PrivatePowOut = >::Output; @@ -199,10 +200,10 @@ where #[test] fn test_inversion() { - type Test4 = <::consts::U4 as Invert>::Output; - type Test5 = <::consts::U5 as Invert>::Output; - type Test12 = <::consts::U12 as Invert>::Output; - type Test16 = <::consts::U16 as Invert>::Output; + type Test4 = ::Output; + type Test5 = ::Output; + type Test12 = ::Output; + type Test16 = ::Output; assert_eq!(1, ::to_u64()); assert_eq!(5, ::to_u64()); @@ -260,10 +261,10 @@ where #[test] fn test_double_inversion() { - type Test4 = <<::consts::U4 as Invert>::Output as Invert>::Output; - type Test5 = <<::consts::U5 as Invert>::Output as Invert>::Output; - type Test12 = <<::consts::U12 as Invert>::Output as Invert>::Output; - type Test16 = <<::consts::U16 as Invert>::Output as Invert>::Output; + type Test4 = <::Output as Invert>::Output; + type Test5 = <::Output as Invert>::Output; + type Test12 = <::Output as Invert>::Output; + type Test16 = <::Output as Invert>::Output; assert_eq!(4, ::to_u64()); assert_eq!(5, ::to_u64()); @@ -320,7 +321,7 @@ where pub trait PrivateCmp { type Output; - fn private_cmp(&self, &Rhs, SoFar) -> Self::Output; + fn private_cmp(&self, _: &Rhs, _: SoFar) -> Self::Output; } pub type PrivateCmpOut = >::Output; @@ -328,7 +329,7 @@ pub type PrivateCmpOut = >::Output; pub trait PrivateSetBit { type Output; - fn private_set_bit(self, I, B) -> Self::Output; + fn private_set_bit(self, _: I, _: B) -> Self::Output; } pub type PrivateSetBitOut = >::Output; @@ -337,9 +338,9 @@ pub trait PrivateDiv { type Quotient; type Remainder; - fn private_div_quotient(self, N, D, Q, R, I) -> Self::Quotient; + fn private_div_quotient(self, _: N, _: D, _: Q, _: R, _: I) -> Self::Quotient; - fn private_div_remainder(self, N, D, Q, R, I) -> Self::Remainder; + fn private_div_remainder(self, _: N, _: D, _: Q, _: R, _: I) -> Self::Remainder; } pub type PrivateDivQuot = <() as PrivateDiv>::Quotient; @@ -349,9 +350,9 @@ pub trait PrivateDivIf { type Quotient; type Remainder; - fn private_div_if_quotient(self, N, D, Q, R, I, RcmpD) -> Self::Quotient; + fn private_div_if_quotient(self, _: N, _: D, _: Q, _: R, _: I, _: RcmpD) -> Self::Quotient; - fn private_div_if_remainder(self, N, D, Q, R, I, RcmpD) -> Self::Remainder; + fn private_div_if_remainder(self, _: N, _: D, _: Q, _: R, _: I, _: RcmpD) -> Self::Remainder; } pub type PrivateDivIfQuot = @@ -363,38 +364,38 @@ pub type PrivateDivIfRem = pub trait PrivateDivInt { type Output; - fn private_div_int(self, C, Divisor) -> Self::Output; + fn private_div_int(self, _: C, _: Divisor) -> Self::Output; } pub type PrivateDivIntOut = >::Output; pub trait PrivateRem { type Output; - fn private_rem(self, URem, Divisor) -> Self::Output; + fn private_rem(self, _: URem, _: Divisor) -> Self::Output; } pub type PrivateRemOut = >::Output; // min max pub trait PrivateMin { type Output; - fn private_min(self, Rhs) -> Self::Output; + fn private_min(self, rhs: Rhs) -> Self::Output; } pub type PrivateMinOut = >::Output; pub trait PrivateMax { type Output; - fn private_max(self, Rhs) -> Self::Output; + fn private_max(self, rhs: Rhs) -> Self::Output; } pub type PrivateMaxOut = >::Output; // Comparisons -use {Equal, False, Greater, Less, True}; +use crate::{Equal, False, Greater, Less, True}; pub trait IsLessPrivate { type Output: Bit; - fn is_less_private(self, Rhs, Cmp) -> Self::Output; + fn is_less_private(self, _: Rhs, _: Cmp) -> Self::Output; } impl IsLessPrivate for A { @@ -425,7 +426,7 @@ impl IsLessPrivate for A { pub trait IsEqualPrivate { type Output: Bit; - fn is_equal_private(self, Rhs, Cmp) -> Self::Output; + fn is_equal_private(self, _: Rhs, _: Cmp) -> Self::Output; } impl IsEqualPrivate for A { @@ -456,7 +457,7 @@ impl IsEqualPrivate for A { pub trait IsGreaterPrivate { type Output: Bit; - fn is_greater_private(self, Rhs, Cmp) -> Self::Output; + fn is_greater_private(self, _: Rhs, _: Cmp) -> Self::Output; } impl IsGreaterPrivate for A { @@ -487,7 +488,7 @@ impl IsGreaterPrivate for A { pub trait IsLessOrEqualPrivate { type Output: Bit; - fn is_less_or_equal_private(self, Rhs, Cmp) -> Self::Output; + fn is_less_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output; } impl IsLessOrEqualPrivate for A { @@ -518,7 +519,7 @@ impl IsLessOrEqualPrivate for A { pub trait IsNotEqualPrivate { type Output: Bit; - fn is_not_equal_private(self, Rhs, Cmp) -> Self::Output; + fn is_not_equal_private(self, _: Rhs, _: Cmp) -> Self::Output; } impl IsNotEqualPrivate for A { @@ -549,7 +550,7 @@ impl IsNotEqualPrivate for A { pub trait IsGreaterOrEqualPrivate { type Output: Bit; - fn is_greater_or_equal_private(self, Rhs, Cmp) -> Self::Output; + fn is_greater_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output; } impl IsGreaterOrEqualPrivate for A { diff --git a/src/type_operators.rs b/src/type_operators.rs index 4a3d440b5..b6901df23 100644 --- a/src/type_operators.rs +++ b/src/type_operators.rs @@ -1,8 +1,9 @@ //! Useful **type operators** that are not defined in `core::ops`. -//! -use private::{Internal, InternalMarker}; -use {Bit, NInt, NonZero, PInt, UInt, UTerm, Unsigned, Z0}; +use crate::{ + private::{Internal, InternalMarker}, + Bit, NInt, NonZero, PInt, UInt, UTerm, Unsigned, Z0, +}; /// A **type operator** that ensures that `Rhs` is the same as `Self`, it is mainly useful /// for writing macros that can take arbitrary binary or unary operators. @@ -222,7 +223,7 @@ impl_pow_i!(u128, i128); #[test] fn pow_test() { - use consts::*; + use crate::consts::*; let z0 = Z0::new(); let p3 = P3::new(); @@ -284,13 +285,13 @@ pub trait Cmp { type Output; #[doc(hidden)] - fn compare(&self, &Rhs) -> Self::Output; + fn compare(&self, _: &Rhs) -> Self::Output; } /// A **type operator** that gives the length of an `Array` or the number of bits in a `UInt`. pub trait Len { /// The length as a type-level unsigned integer. - type Output: ::Unsigned; + type Output: crate::Unsigned; /// This function isn't used in this crate, but may be useful for others. fn len(&self) -> Self::Output; } @@ -320,7 +321,7 @@ pub trait Max { fn max(self, rhs: Rhs) -> Self::Output; } -use Compare; +use crate::Compare; /// A **type operator** that returns `True` if `Self < Rhs`, otherwise returns `False`. pub trait IsLess { @@ -330,7 +331,7 @@ pub trait IsLess { fn is_less(self, rhs: Rhs) -> Self::Output; } -use private::IsLessPrivate; +use crate::private::IsLessPrivate; impl IsLess for A where A: Cmp + IsLessPrivate>, @@ -352,7 +353,7 @@ pub trait IsEqual { fn is_equal(self, rhs: Rhs) -> Self::Output; } -use private::IsEqualPrivate; +use crate::private::IsEqualPrivate; impl IsEqual for A where A: Cmp + IsEqualPrivate>, @@ -374,7 +375,7 @@ pub trait IsGreater { fn is_greater(self, rhs: Rhs) -> Self::Output; } -use private::IsGreaterPrivate; +use crate::private::IsGreaterPrivate; impl IsGreater for A where A: Cmp + IsGreaterPrivate>, @@ -396,7 +397,7 @@ pub trait IsLessOrEqual { fn is_less_or_equal(self, rhs: Rhs) -> Self::Output; } -use private::IsLessOrEqualPrivate; +use crate::private::IsLessOrEqualPrivate; impl IsLessOrEqual for A where A: Cmp + IsLessOrEqualPrivate>, @@ -418,7 +419,7 @@ pub trait IsNotEqual { fn is_not_equal(self, rhs: Rhs) -> Self::Output; } -use private::IsNotEqualPrivate; +use crate::private::IsNotEqualPrivate; impl IsNotEqual for A where A: Cmp + IsNotEqualPrivate>, @@ -440,7 +441,7 @@ pub trait IsGreaterOrEqual { fn is_greater_or_equal(self, rhs: Rhs) -> Self::Output; } -use private::IsGreaterOrEqualPrivate; +use crate::private::IsGreaterOrEqualPrivate; impl IsGreaterOrEqual for A where A: Cmp + IsGreaterOrEqualPrivate>, diff --git a/src/uint.rs b/src/uint.rs index 1d09c78cf..e9c3611d7 100644 --- a/src/uint.rs +++ b/src/uint.rs @@ -3,7 +3,7 @@ //! //! **Type operators** implemented: //! -//! From `core::ops`: `BitAnd`, `BitOr`, `BitXor`, `Shl`, `Shr`, `Add`, `Sub`, +//! From `::core::ops`: `BitAnd`, `BitOr`, `BitXor`, `Shl`, `Shr`, `Add`, `Sub`, //! `Mul`, `Div`, and `Rem`. //! From `typenum`: `Same`, `Cmp`, and `Pow`. //! @@ -26,31 +26,22 @@ //! assert_eq!(>::Output::to_u32(), 1); //! assert_eq!(>::Output::to_u32(), 1); //! ``` -//! - -use core::ops::{Add, BitAnd, BitOr, BitXor, Mul, Shl, Shr, Sub}; -use { - Cmp, Equal, Gcd, Greater, IsGreaterOrEqual, Len, Less, Logarithm2, Maximum, Minimum, NonZero, - Ord, Pow, SquareRoot, -}; - -use bit::{Bit, B0, B1}; -use private::{ - BitDiff, PrivateAnd, PrivateCmp, PrivateLogarithm2, PrivatePow, PrivateSquareRoot, PrivateSub, - PrivateXor, Trim, +use crate::{ + bit::{Bit, B0, B1}, + consts::{U0, U1}, + private::{ + BitDiff, BitDiffOut, Internal, InternalMarker, PrivateAnd, PrivateAndOut, PrivateCmp, + PrivateCmpOut, PrivateLogarithm2, PrivatePow, PrivatePowOut, PrivateSquareRoot, PrivateSub, + PrivateSubOut, PrivateXor, PrivateXorOut, Trim, TrimOut, + }, + Add1, Cmp, Double, Equal, Gcd, Gcf, GrEq, Greater, IsGreaterOrEqual, Len, Length, Less, Log2, + Logarithm2, Maximum, Minimum, NonZero, Or, Ord, Pow, Prod, Shleft, Shright, Sqrt, Square, + SquareRoot, Sub1, Sum, }; +use core::ops::{Add, BitAnd, BitOr, BitXor, Mul, Shl, Shr, Sub}; -use private::{ - BitDiffOut, PrivateAndOut, PrivateCmpOut, PrivatePowOut, PrivateSubOut, PrivateXorOut, TrimOut, -}; - -use private::{Internal, InternalMarker}; - -use consts::{U0, U1}; -use {Add1, Double, Gcf, GrEq, Length, Log2, Or, Prod, Shleft, Shright, Sqrt, Square, Sub1, Sum}; - -pub use marker_traits::{PowerOfTwo, Unsigned}; +pub use crate::marker_traits::{PowerOfTwo, Unsigned}; /// The terminating type for `UInt`; it always comes after the most significant /// bit. `UTerm` by itself represents zero, which is aliased to `U0`. @@ -1289,7 +1280,7 @@ where // --------------------------------------------------------------------------------------- // Shifting one number until it's the size of another -use private::ShiftDiff; +use crate::private::ShiftDiff; impl ShiftDiff for Ul where Ur: BitDiff