Merge branch 'main' into rpc-handler

This commit is contained in:
hinto.janai 2024-09-02 17:48:04 -04:00
commit 57677a5e90
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
2 changed files with 11 additions and 9 deletions

View file

@ -4,6 +4,8 @@
//!
//! `#[no_std]` compatible.
#![allow(clippy::cast_possible_truncation)]
#[rustfmt::skip]
//============================ SAFETY: DO NOT REMOVE ===========================//
// //
@ -60,8 +62,8 @@ mod test {
#[test]
fn max_unsigned() {
assert_eq!(u32_to_usize(u32::MAX), u32::MAX as usize);
assert_eq!(usize_to_u64(u32_to_usize(u32::MAX)), u32::MAX as u64);
assert_eq!(u32_to_usize(u32::MAX), usize::try_from(u32::MAX).unwrap());
assert_eq!(usize_to_u64(u32_to_usize(u32::MAX)), u64::from(u32::MAX));
assert_eq!(u64_to_usize(u64::MAX), usize::MAX);
assert_eq!(usize_to_u64(u64_to_usize(u64::MAX)), u64::MAX);
@ -72,8 +74,8 @@ mod test {
#[test]
fn max_signed() {
assert_eq!(i32_to_isize(i32::MAX), i32::MAX as isize);
assert_eq!(isize_to_i64(i32_to_isize(i32::MAX)), i32::MAX as i64);
assert_eq!(i32_to_isize(i32::MAX), isize::try_from(i32::MAX).unwrap());
assert_eq!(isize_to_i64(i32_to_isize(i32::MAX)), i64::from(i32::MAX));
assert_eq!(i64_to_isize(i64::MAX), isize::MAX);
assert_eq!(isize_to_i64(i64_to_isize(i64::MAX)), i64::MAX);

View file

@ -76,7 +76,7 @@ pub const fn combine_low_high_bits_to_u128(low_bits: u64, high_bits: u64) -> u12
/// assert_eq!(u64_to_timelock(499_999_999), Timelock::Block(499_999_999));
/// assert_eq!(u64_to_timelock(500_000_000), Timelock::Time(500_000_000));
/// ```
pub fn u64_to_timelock(u: u64) -> Timelock {
pub const fn u64_to_timelock(u: u64) -> Timelock {
if u == 0 {
Timelock::None
} else if u < 500_000_000 {
@ -97,7 +97,7 @@ pub fn u64_to_timelock(u: u64) -> Timelock {
/// assert_eq!(timelock_to_u64(Timelock::Block(499_999_999)), 499_999_999);
/// assert_eq!(timelock_to_u64(Timelock::Time(500_000_000)), 500_000_000);
/// ```
pub fn timelock_to_u64(timelock: Timelock) -> u64 {
pub const fn timelock_to_u64(timelock: Timelock) -> u64 {
match timelock {
Timelock::None => 0,
Timelock::Block(u) => usize_to_u64(u),