Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,17 @@ 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
}

Expand All @@ -136,8 +133,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
}

Expand All @@ -148,8 +144,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
}

Expand Down
10 changes: 3 additions & 7 deletions uint/src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,13 @@ 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]
}
Expand Down Expand Up @@ -600,8 +598,7 @@ macro_rules! construct_uint {
/// # Panics
///
/// 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
}
Expand Down Expand Up @@ -641,7 +638,6 @@ macro_rules! construct_uint {
}

/// Zero (additive identity) of this type.
#[inline]
pub const fn zero() -> Self {
Self([0; $n_words])
}
Expand Down