Allow private uint definition and crunchy convenience fix

This commit is contained in:
Wei Tang 2018-12-03 12:56:37 +08:00
parent ac6914908c
commit 552b0f77bb
4 changed files with 18 additions and 11 deletions

View File

@ -16,7 +16,7 @@ quickcheck = { version = "0.6", optional = true }
crunchy = { version = "0.2", default-features = true }
[features]
default = ["std", "common"]
default = ["std"]
std = ["byteorder/std", "rustc-hex/std", "crunchy/std"]
common = []

View File

@ -9,13 +9,12 @@
#[cfg(feature="std")]
extern crate core;
#[macro_use]
extern crate crunchy;
#[macro_use]
extern crate uint;
construct_uint!(U256, 4);
construct_uint! {
pub struct U256(4);
}
fn main() {
// Example modular arithmetic using bigint U256 primitives

View File

@ -29,8 +29,8 @@ pub extern crate rustc_hex;
#[doc(hidden)]
pub extern crate quickcheck;
#[macro_use]
extern crate crunchy;
pub use crunchy::unroll;
#[macro_use]
mod uint;
@ -38,8 +38,15 @@ pub use uint::*;
#[cfg(feature = "common")]
mod common {
construct_uint!(U256, 4);
construct_uint!(U512, 8);
construct_uint! {
/// Little-endian 256-bit integer type.
pub struct U256(4);
}
construct_uint! {
/// Little-endian 512-bit integer type.
pub struct U512(8);
}
#[doc(hidden)]
impl U256 {

View File

@ -346,11 +346,12 @@ pub fn split_u128(a: u128) -> (u64, u64) {
#[macro_export]
macro_rules! construct_uint {
($name:ident, $n_words: tt) => (
( $(#[$attr:meta])* $visibility:vis struct $name:ident ( $n_words:tt ); ) => {
/// Little-endian large integer type
#[repr(C)]
$(#[$attr])*
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub struct $name(pub [u64; $n_words]);
$visibility struct $name ([u64; $n_words]);
impl AsRef<$name> for $name {
fn as_ref(&self) -> &$name {
@ -1271,7 +1272,7 @@ macro_rules! construct_uint {
// `$n_words * 8` because macro expects bytes and
// uints use 64 bit (8 byte) words
impl_quickcheck_arbitrary_for_uint!($name, ($n_words * 8));
);
}
}
#[cfg(feature = "std")]