diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index ea2210076..09ce43d8c 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -107,19 +107,19 @@ macro_rules! construct_fixed_hash { impl $name { /// Returns a new fixed hash where all bits are set to the given byte. #[inline] - pub fn repeat_byte(byte: u8) -> $name { + pub const fn repeat_byte(byte: u8) -> $name { $name([byte; $n_bytes]) } /// Returns a new zero-initialized fixed hash. #[inline] - pub fn zero() -> $name { + pub const fn zero() -> $name { $name::repeat_byte(0u8) } /// Returns the size of this hash in bytes. #[inline] - pub fn len_bytes() -> usize { + pub const fn len_bytes() -> usize { $n_bytes } @@ -137,7 +137,7 @@ macro_rules! construct_fixed_hash { /// Extracts a reference to the byte array containing the entire fixed hash. #[inline] - pub fn as_fixed_bytes(&self) -> &[u8; $n_bytes] { + pub const fn as_fixed_bytes(&self) -> &[u8; $n_bytes] { &self.0 } @@ -149,7 +149,7 @@ macro_rules! construct_fixed_hash { /// Returns the inner bytes array. #[inline] - pub fn to_fixed_bytes(self) -> [u8; $n_bytes] { + pub const fn to_fixed_bytes(self) -> [u8; $n_bytes] { self.0 } diff --git a/rlp/src/rlpin.rs b/rlp/src/rlpin.rs index f1c488626..6cdfaa808 100644 --- a/rlp/src/rlpin.rs +++ b/rlp/src/rlpin.rs @@ -25,7 +25,7 @@ struct OffsetCache { } impl OffsetCache { - fn new(index: usize, offset: usize) -> OffsetCache { + const fn new(index: usize, offset: usize) -> OffsetCache { OffsetCache { index, offset } } } @@ -68,7 +68,7 @@ fn calculate_payload_info(header_bytes: &[u8], len_of_len: usize) -> Result PayloadInfo { + const fn new(header_len: usize, value_len: usize) -> PayloadInfo { PayloadInfo { header_len, value_len } } @@ -128,7 +128,7 @@ impl<'a> fmt::Display for Rlp<'a> { } impl<'a> Rlp<'a> { - pub fn new(bytes: &'a [u8]) -> Rlp<'a> { + pub const fn new(bytes: &'a [u8]) -> Rlp<'a> { Rlp { bytes, offset_cache: Cell::new(None), count_cache: Cell::new(None) } } @@ -374,7 +374,7 @@ pub struct BasicDecoder<'a> { } impl<'a> BasicDecoder<'a> { - pub fn new(rlp: &'a [u8]) -> BasicDecoder<'a> { + pub const fn new(rlp: &'a [u8]) -> BasicDecoder<'a> { BasicDecoder { rlp } } diff --git a/uint/src/uint.rs b/uint/src/uint.rs index b15726b72..7dd1bca42 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -371,7 +371,7 @@ macro_rules! construct_uint { impl $name { /// Low 2 words (u128) #[inline] - pub fn low_u128(&self) -> u128 { + pub const fn low_u128(&self) -> u128 { let &$name(ref arr) = self; ((arr[1] as u128) << 64) + arr[0] as u128 } @@ -473,14 +473,14 @@ macro_rules! construct_uint { /// Conversion to u32 #[inline] - pub fn low_u32(&self) -> u32 { + pub const fn low_u32(&self) -> u32 { let &$name(ref arr) = self; arr[0] as u32 } /// Low word (u64) #[inline] - pub fn low_u64(&self) -> u64 { + pub const fn low_u64(&self) -> u64 { let &$name(ref arr) = self; arr[0] } @@ -560,7 +560,7 @@ macro_rules! construct_uint { /// /// Panics if `index` exceeds the bit width of the number. #[inline] - pub fn bit(&self, index: usize) -> bool { + pub const fn bit(&self, index: usize) -> bool { let &$name(ref arr) = self; arr[index / 64] & (1 << (index % 64)) != 0 } @@ -601,7 +601,7 @@ macro_rules! construct_uint { /// /// Panics if `index` exceeds the byte width of the number. #[inline] - pub fn byte(&self, index: usize) -> u8 { + pub const fn byte(&self, index: usize) -> u8 { let &$name(ref arr) = self; (arr[index / 8] >> (((index % 8)) * 8)) as u8 } @@ -1066,18 +1066,18 @@ macro_rules! construct_uint { } #[inline(always)] - fn mul_u64(a: u64, b: u64, carry: u64) -> (u64, u64) { - let (hi, lo) = Self::split_u128(u128::from(a) * u128::from(b) + u128::from(carry)); + const fn mul_u64(a: u64, b: u64, carry: u64) -> (u64, u64) { + let (hi, lo) = Self::split_u128(a as u128 * b as u128 + carry as u128); (lo, hi) } #[inline(always)] - fn split(a: u64) -> (u64, u64) { + const fn split(a: u64) -> (u64, u64) { (a >> 32, a & 0xFFFF_FFFF) } #[inline(always)] - fn split_u128(a: u128) -> (u64, u64) { + const fn split_u128(a: u128) -> (u64, u64) { ((a >> 64) as _, (a & 0xFFFFFFFFFFFFFFFF) as _) }