Fix [u8; $n_words] conversion

Remove unneeded ref conversion impl
Better test value
This commit is contained in:
David Palm 2018-08-22 11:28:11 +02:00
parent 72e84868e8
commit 283b13f114
2 changed files with 7 additions and 11 deletions

View File

@ -816,17 +816,13 @@ macro_rules! construct_uint {
impl From<[u8; $n_words * 8]> for $name {
fn from(bytes: [u8; $n_words * 8]) -> Self {
let bytes : [u64; $n_words] = unsafe { ::core::mem::transmute(bytes) };
let mut bytes = bytes;
bytes[..].reverse();
let bytes : [u64; $n_words] = unsafe { ::core::mem::transmute(bytes)};
$name(bytes)
}
}
impl<'a> From<&'a [u8; $n_words * 8]> for $name {
fn from(bytes: &[u8; $n_words * 8]) -> Self {
bytes[..].into()
}
}
impl Default for $name {
fn default() -> Self {
$name::zero()

View File

@ -1017,14 +1017,14 @@ fn test_u256_from_fixed_array() {
let ary = [
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, 123
0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 123,
];
let num : U256 = ary.into();
assert_eq!( num, U256::from(123) );
assert_eq!( num, U256::from(std::u64::MAX) + 1 + 123);
let a_ref : &U256 = &ary.into();
assert_eq!( a_ref, &U256::from(123) );
assert_eq!( a_ref, &(U256::from(std::u64::MAX) + 1 + 123));
}
#[test]