Move conversion inside macro
This commit is contained in:
parent
b4b5c6f626
commit
9261b8519e
|
@ -806,6 +806,13 @@ macro_rules! construct_uint {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<$name> for [u8; $n_words * 8] {
|
||||
fn from(number: $name) -> Self {
|
||||
let mut arr = [0u8; $n_words * 8];
|
||||
number.to_big_endian(&mut arr);
|
||||
arr
|
||||
}
|
||||
}
|
||||
impl Default for $name {
|
||||
fn default() -> Self {
|
||||
$name::zero()
|
||||
|
@ -1369,12 +1376,4 @@ macro_rules! impl_quickcheck_arbitrary_for_uint {
|
|||
}
|
||||
|
||||
construct_uint!(U256, 4);
|
||||
construct_uint!(U512, 8);
|
||||
|
||||
impl From<U256> for [u8; 32] {
|
||||
fn from(number: U256) -> Self {
|
||||
let mut arr = [0u8; 32];
|
||||
number.to_big_endian(&mut arr);
|
||||
arr
|
||||
}
|
||||
}
|
||||
construct_uint!(U512, 8);
|
|
@ -1000,6 +1000,18 @@ fn from_big_endian() {
|
|||
assert_eq!(U256::from(1), number);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_fixed_array() {
|
||||
let expected: [u8; 32] = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 1,
|
||||
];
|
||||
let ary : [u8; 32] = U256::from(1).into();
|
||||
assert_eq!(ary, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leading_zeros() {
|
||||
assert_eq!(U256::from("000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").leading_zeros(), 95);
|
||||
|
|
Loading…
Reference in New Issue