Skip to content

Commit

Permalink
Merge branch 'jerry73204-2018-edition'
Browse files Browse the repository at this point in the history
  • Loading branch information
paholg committed Mar 12, 2021
2 parents 80fbdeb + f4305c3 commit 1043b4c
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 134 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -255,7 +254,7 @@ impl Cmp<B1> for B1 {
}
}

use Min;
use crate::Min;
impl Min<B0> for B0 {
type Output = B0;
#[inline]
Expand Down Expand Up @@ -285,7 +284,7 @@ impl Min<B1> for B1 {
}
}

use Max;
use crate::Max;
impl Max<B0> for B0 {
type Output = B0;
#[inline]
Expand Down
27 changes: 12 additions & 15 deletions src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@
//! assert_eq!(<N3 as Div<P2>>::Output::to_i32(), -1);
//! assert_eq!(<N3 as Rem<P2>>::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<U: Unsigned + NonZero> {
Expand Down Expand Up @@ -610,7 +608,7 @@ impl_int_div!(NInt, NInt, PInt);
// ---------------------------------------------------------------------------------------
// PartialDiv

use {PartialDiv, Quot};
use crate::{PartialDiv, Quot};

impl<M, N> PartialDiv<N> for M
where
Expand Down Expand Up @@ -888,7 +886,7 @@ where

// ---------------------------------------------------------------------------------------
// Gcd
use {Gcd, Gcf};
use crate::{Gcd, Gcf};

impl Gcd<Z0> for Z0 {
type Output = Z0;
Expand Down Expand Up @@ -960,7 +958,7 @@ where

// ---------------------------------------------------------------------------------------
// Min
use {Max, Maximum, Min, Minimum};
use crate::{Max, Maximum, Min, Minimum};

impl Min<Z0> for Z0 {
type Output = Z0;
Expand Down Expand Up @@ -1179,8 +1177,7 @@ where

#[cfg(test)]
mod tests {
use consts::*;
use Integer;
use crate::{consts::*, Integer};

#[test]
fn to_ix_min() {
Expand Down
25 changes: 14 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -141,14 +142,16 @@ 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;
};
}

/// Asserts that a type is `True`, aka `B1`.
#[macro_export]
macro_rules! assert_type {
($a:ty) => {
const _: core::marker::PhantomData<<$a as $crate::Same<True>>::Output> = core::marker::PhantomData;
const _: core::marker::PhantomData<<$a as $crate::Same<True>>::Output> =
core::marker::PhantomData;
};
}
16 changes: 9 additions & 7 deletions src/operator_aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
//!
//! ```rust
//! # #[macro_use] extern crate typenum;
//! # fn main() {
//! use std::ops::Mul;
//! use typenum::{Prod, P5, P7};
//!
//! type X = <P7 as Mul<P5>>::Output;
//! type Y = Prod<P7, P5>;
//!
//! 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<A, B> = <A as BitAnd<B>>::Output`
pub type And<A, B> = <A as BitAnd<B>>::Output;
Expand Down Expand Up @@ -64,12 +64,12 @@ pub type Exp<A, B> = <A as Pow<B>>::Output;
pub type Gcf<A, B> = <A as Gcd<B>>::Output;

/// Alias to make it easy to add 1: `Add1<A> = <A as Add<B1>>::Output`
pub type Add1<A> = <A as Add<::bit::B1>>::Output;
pub type Add1<A> = <A as Add<crate::bit::B1>>::Output;
/// Alias to make it easy to subtract 1: `Sub1<A> = <A as Sub<B1>>::Output`
pub type Sub1<A> = <A as Sub<::bit::B1>>::Output;
pub type Sub1<A> = <A as Sub<crate::bit::B1>>::Output;

/// Alias to make it easy to multiply by 2. `Double<A> = Shleft<A, B1>`
pub type Double<A> = Shleft<A, ::bit::B1>;
pub type Double<A> = Shleft<A, crate::bit::B1>;

/// Alias to make it easy to square. `Square<A> = <A as Mul<A>>::Output`
pub type Square<A> = <A as Mul>::Output;
Expand All @@ -91,7 +91,9 @@ pub type Minimum<A, B> = <A as Min<B>>::Output;
/// Alias for the associated type of `Max`: `Maximum<A, B> = <A as Max<B>>::Output`
pub type Maximum<A, B> = <A as Max<B>>::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<A, B> = <A as IsLess<B>>::Output`
pub type Le<A, B> = <A as IsLess<B>>::Output;
/// Alias for the associated type of `IsEqual`: `Eq<A, B> = <A as IsEqual<B>>::Output`
Expand Down
Loading

0 comments on commit 1043b4c

Please sign in to comment.